Find the answer to your Linux question:
Results 1 to 4 of 4
Hi, Never seen this issue before, tried googling, but never found anyone with the same problem. I have a very simple shell script which aims to remove directories based on ...
  1. #1
    Just Joined!
    Join Date
    Mar 2007
    Posts
    3

    rm from script will not run, but will run from console

    Hi,

    Never seen this issue before, tried googling, but never found anyone with the same problem. I have a very simple shell script which aims to remove directories based on time of day.

    Here is the script:

    #!/bin/bash
    #Script to remove pcap files after a few hours

    hostname=`hostname`
    echo hostname is $hostname

    currentHour=`date +%H`
    echo currentHour is $currentHour

    workingDirectory=/var/lib/es/home/pcapsipdump/`hostname`/
    echo workingDirectory is $workingDirectory

    hoursToStore=$1
    echo hoursToStore is $hoursToStore

    hourToRemove=`date +%H --date "$hoursToStore hours ago"`
    echo hourToRemove is $hourToRemove

    chown -R es:es /var/lib/enswitch/home/
    chmod 777 -R /var/lib/es/home/pcapsipdump/

    echo removing $workingDirectory`date +%Y%m%d`/$hourToRemove/
    echo rm -rfv $workingDirectory`date +%Y%m%d`/$hourToRemove/


    This is the output I get when I run the command: directory remains untouched

    [root@enlab1 bin]# ./remove_old_pcaps.sh 7
    hostname is enlab1
    currentHour is 15
    workingDirectory is /var/lib/es/home/pcapsipdump/enlab1/
    hoursToStore is 7
    hourToRemove is 08
    removing /var/lib/es/home/pcapsipdump/enlab1/20090219/08/
    rm -rfv /var/lib/es/home/pcapsipdump/enlab1/20090219/08/


    If I go out to the linux cli and do

    rm -rfv /var/lib/es/home/pcapsipdump/enlab1/20090219/08/

    it deletes all the files and shows them on screen as it is deleting them

    I get no errors from my script when I run it. Plus permissions are set to 777 and the same owner as the script is being run as. Tried running the script as root, but still to no avail.

    Is there anything that would cause something to not run from a basic script like this, but yet will from the command line itself?

    Thanks in advance for any advice

    Robert

  2. #2
    Linux User
    Join Date
    May 2008
    Location
    NYC, moved from KS & MO
    Posts
    251
    echo rm -rfv $workingDirectory`date +%Y%m%d`/$hourToRemove/
    Of course it will not rm the destination if you put echo in front of it.

  3. #3
    Linux User
    Join Date
    Jun 2007
    Posts
    318
    You have an 'echo' in front of the 'rm' command so the script just prints the command instead of executing it. Remove the 'echo'.

  4. #4
    Just Joined!
    Join Date
    Mar 2007
    Posts
    3
    thanks guys, never seen it, little embarassed now - I was just looking at the output from the script and not looking at the script enough

    I will hang my head in shame

    R

Posting Permissions

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