1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

need help with my cron script

Discussion in 'Linux and Unix' started by mushka, Feb 10, 2005.

Thread Status:
Not open for further replies.
Advertisement
  1. mushka

    mushka Thread Starter

    Joined:
    Sep 21, 2004
    Messages:
    51
    Hi there, I'm very new to shell scripting so this may be incredibly simple to someone but:-

    I've started using cron to automate some simple spam relocation and destruction. I want to see if there's a file called robinspam in dir /home/robin, and if there is I want to copy it, rename it, then move the copy to a folder and chmod it so anyone can read it from the ftp site. I'm getting a ' [ -e command not found ' message from cron when it tries to run it.

    anyway here's the script. any help greatly appreciated as usual.
    chz
    ben

    #!/bin/bash
    if [-e /home/robin/robinspam ] ; then

    cp /home/robin/spam /home/robin/robinspam
    echo spam was found in mail directory robin

    mv -f /home/robin/robinspam /ftpfolder/robinspam.txt
    echo spam was duplicated and moved to the ftp folder

    chmod o+r /ftpfolder/robinspam.txt
    echo chmod on the file was successful anyone can read the file now

    else
    echo there was no spam found for user robin

    fi
     
  2. Squashman

    Squashman Trusted Advisor

    Joined:
    Apr 4, 2003
    Messages:
    19,786
    Shouldn't this be the other way around. You are testing to see if robinspam exists but then you are copying some other file called spam to robinspam. I thought you wanted to copy robinspam to another filename.

    You are getting that error because you dont have a space after the first Bracket before the hypen and e.
     
  3. Squashman

    Squashman Trusted Advisor

    Joined:
    Apr 4, 2003
    Messages:
    19,786
    One more thing. Why dont you just eliminate the move command and just use the copy command to move and rename the file at the same time.

    cp /home/robin/spam /ftpfolder/robinspam.txt
     
  4. mushka

    mushka Thread Starter

    Joined:
    Sep 21, 2004
    Messages:
    51
    I thought i was doing something stupid. wood for the trees
    cheers
    ben
     
  5. mushka

    mushka Thread Starter

    Joined:
    Sep 21, 2004
    Messages:
    51
    although, I was being daft and had made a mistake with the filenames, the "command not found" problem persisted. But it was cured by adding a space after the square brackets and before the -e.
    eg
    if [ -e /home/robin/spam ]

    as opposed to

    if [-e /home/robin/spam ]

    just in case anyone is having a similar error message
     
  6. Squashman

    Squashman Trusted Advisor

    Joined:
    Apr 4, 2003
    Messages:
    19,786
    Isn't that what I said in my first post.
     
  7. mushka

    mushka Thread Starter

    Joined:
    Sep 21, 2004
    Messages:
    51
    oops, sorry Squashman,
    you are of course completely correct.
    more haste less speed required on my part.
    cheers again, and I promise to read further posts in their entirety.
    ben
     
  8. Sponsor

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/328835

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice