PDA

Bekijk de volledige versie : Script with rm or sed command



Jarex
17-06-2007, 11:08
I am trying to make small script like this editing or removing post-firewall:


#!/bin/sh
wget -q -O - ftp://login:pass@ip/log/temp.log > /opt/tmp/test.log
if test -s /opt/tmp/test.log
then echo "file exist, doing nothing..."
else sed -i "3,//d" /tmp/local/sbin/post-firewall
fi

Whenever I check script with sh -x it looks like the else command cannot be done (else sed -i "3,//d" /usr/local/sbin/post-firewall or else rm /usr/local/sbin/post-firewall). Script does not see file "post-firewall" and do not want to edit it.

What am I doing wrong?

Ade
17-06-2007, 22:52
Your if statement should look something like :-


if [ -e /opt/tmp/test.log ]; then echo "yes"; else echo "no"; fi

The square brackets can be replaced by your test statement but the semi colons are important.

Cheers

Ade

Jarex
18-06-2007, 10:35
It's not working with semicolons. But I found a solution. To use rm or sed command I have to add #! /bin/rm and #!/ bin/sed, don't know why it doesn't find the rignt path withouth it.

#! /bin/sh
#! /bin/rm
wget -q -O - ftp://login:pass@ip/log/temp.log > /opt/tmp/test.log
if test -s /opt/tmp/test.log
then echo "file exist, doing nothing..."
else rm /usr/local/sbin/post-firewall || rm /opt/var/log/test.txt || . /opt/share/scripts/flash start
fi

Jarex
18-06-2007, 17:30
One more question. Instead of use script on desire machine I would like to use script or command on remote machine to e.g. remove a file.

Anyone can help?

al37919
19-06-2007, 08:59
If I understand you question correctly it can be done using expect. It is tool for automation of interactive tasks. Here you can see example code using expect how to remotely reboot ADSL modem, and expect itself (+ tcl, which it needs) http://wl500g.info/showpost.php?p=55065&postcount=5

Second possibility is telnet.pm module for perl (probably exists also similar module for ftp)