Skip to content

Tag: shell

if host pings execute command

#!/bin/sh
HOST="silveiraneto.net"
if ping -c 1 $HOST > /dev/null
then
   echo your command
fi
  • replace silveiraneto.net for your desired hostname or ip
  • ping sends only one package (-c 1) and ignores the text output
  • a ping is successful returns 0 and the if proceeds
  • replace the echo line with your command

Congelando e Ressuscitando Processos

batman mr freeze

Nem só de morte vive o kill.

Suponha que você tem um processo chamado program e quer congelar seu funcionamento. Para congela-lo sem mata-lo você pode mandar um sinal SIGSTOP com:

kill -s stop `pidof program`

Para ressuscitar o mesmo processo:

kill -s cont `pidof program`

Creating a lot of thumbnails with Shell script

This script create a thumbnail with width 100 of each png file in the actual directory.

#!/bin/sh
for i in *.png
do
	echo "convert -thumbnail 100 $i $i"
	convert -thumbnail 100 $i $i
done