Shell scripts

From Igor personal wiki
Jump to: navigation, search

Pass file content as a command line arguments

./myscript.sh $(cat mycmds.txt)

The $(xyz) construct runs xyz then uses its standard output to construct that part of the command.


Endless loop:

#!/bin/bash
while true
do
curl "http://dgw.test.net:80/api/chatlaunch/"
sleep 1
done

History without line numbers

$ history | cut -c 8-

Killing all ssh sessions

kill $(ps --ppid 1241 -o pid h)

where --ppid 1241 -- your sshd proccess id.

Self updating centos script

# vi /etc/cron.daily/self_update

#!/bin/sh
if  [[ "$HOSTNAME" == y??0?centos?tmpl* ]]; 
then /usr/bin/yum update -y > /var/log/self_update.log 2>&1
else
/bin/rm -v /etc/cron.daily/self_update > /var/log/self_update.log 2>&1 
fi
exit 0

# chmod u+x,g+x,o+x /etc/cron.daily/self_update

Rsync

/usr/bin/rsync --delete --progress -havze 'ssh -i /home/automation/.ssh/id_dsa' --rsync-path="sudo /usr/bin/rsync" /opt/software automation@10.10.70.12:/opt/

Wget

Mirrow site Download Only Certain File Types Using wget -r -A

Download all PDF files from a website
wget -r -A.pdf http://url-to-webpage-with-pdfs/