Bash - Shellcode en vrac
Alasta 11 Décembre 2015 bash bash shell cli
Description : Voici quelques morceaux de shellcodes.
Lire un fichier ligne à ligne :
while IFS= read -r ligne
do
echo $ligne
done <fichier.log
Avoir la date d’il y a X jours :
#Le jour précédent
date --date='1 days ago' +%Y%m%d
#Il y a 1 mois
date --date='1 months ago' +%Y%m%d
#Dernier jours du mois ou la date :
date -d "2013-01-01 +1 month -1 day" +%d
#Date avec heure :
date +%Y%m%d_%H%M%S
Redirection :
# rediriger stdout seul
hello01.pl > hello01.log
# rediriger stderr seul
hello01.pl 2> hello01.err
# rediriger stdout + stderr
hello01.pl &> hello01.all
qui est équivalent à
hello01.pl 1>hello01.all 2>&1
Rechercher un fichier avec un inode :
find / -inum _#inode_
ou
debugfs -R 'ncheck 296488178' /dev/mapper/vg0-lv_appli
Informations sur une connexion SSH :
SSH_CLIENT='192.168.223.17 36673 22'
SSH_CONNECTION='192.168.223.17 36673 192.168.223.229 22'
SSH_TTY=/dev/pts/6
=> pas d’info en root si passage via su
Fichier tar avec la date
#--selinux permet de garder les contextes SELinux
tar --selinux -czvf ./backup-"$(date +%Y%m%d_%H%M%S)".tar.gz /mes/fichiers/