Results 1 to 5 of 5

Thread: Script with rm or sed command

  1. #1

    Script with rm or sed command

    I am trying to make small script like this editing or removing post-firewall:

    PHP Code:
    #!/bin/sh
    wget --ftp://login:pass@ip/log/temp.log > /opt/tmp/test.log
    if test -/opt/tmp/test.log
    then 
    echo "file exist, doing nothing..."
    else sed -"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?

  2. #2
    Your if statement should look something like :-

    Code:
    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

  3. #3
    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 --ftp://login:pass@ip/log/temp.log > /opt/tmp/test.log
    if test -/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 

  4. #4
    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?

  5. #5
    Join Date
    Feb 2007
    Location
    Moscow, Russia
    Posts
    3,805
    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)

Similar Threads

  1. FTP сервер.
    By gish in forum Russian Discussion - РУССКИЙ (RU)
    Replies: 171
    Last Post: 26-04-2011, 17:46
  2. Update NoIp, DynDNS, dyn.ee, ipactive via script
    By rj.2001 in forum WL-500g/WL-500gx Tutorials
    Replies: 9
    Last Post: 04-01-2011, 15:48
  3. Maintainin multiple dyndns accounts from wl500g.
    By ikerstges in forum WL-500g/WL-500gx Tutorials
    Replies: 9
    Last Post: 21-03-2008, 20:12
  4. Call script from post-boot and not returing?
    By scriptman in forum WL-500gP Q&A
    Replies: 2
    Last Post: 04-12-2006, 03:56
  5. Problem with Samba
    By bs3 in forum WL-500g Q&A
    Replies: 16
    Last Post: 24-05-2005, 09:42

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •