Your if statement should look something like :-
The square brackets can be replaced by your test statement but the semi colons are important.Code:if [ -e /opt/tmp/test.log ]; then echo "yes"; else echo "no"; fi
Cheers
Ade
I am trying to make small script like this editing or removing post-firewall:
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.PHP Code:
#!/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
What am I doing wrong?
Your if statement should look something like :-
The square brackets can be replaced by your test statement but the semi colons are important.Code:if [ -e /opt/tmp/test.log ]; then echo "yes"; else echo "no"; fi
Cheers
Ade
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.
PHP Code:
#! /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
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?
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)