There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
Search
Linux and Unix
Tag Cloud
access acer asus bios bsod computer crash dns driver drivers error ethernet excel freeze gaming hard drive hardware hdmi internet laptop lcd malware memory missing monitor motherboard network operating system printer problem ram registry router slow software sound toshiba trojan usb video virus vista wifi windows windows 7 windows 7 32 bit windows 7 64 bit windows xp wireless xbox
Search
Search for:
Tech Support Guy Forums > Operating Systems > Linux and Unix >
need help with my cron script

Reply  
Thread Tools
mushka's Avatar
Member with 51 posts.
 
Join Date: Sep 2004
Experience: much to learn
10-Feb-2005, 09:16 AM #1
need help with my cron script
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
Squashman's Avatar
Trusted Advisor with 18,705 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
Experience: Bocks of Rox
10-Feb-2005, 11:30 AM #2
Quote:
Originally Posted by mushka
#!/bin/bash
if [-e /home/robin/robinspam ] ; then

cp /home/robin/spam /home/robin/robinspam
echo spam was found in mail directory robin
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.

Last edited by LwdSquashman; 10-Feb-2005 at 11:48 AM..
Squashman's Avatar
Trusted Advisor with 18,705 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
Experience: Bocks of Rox
10-Feb-2005, 11:51 AM #3
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
mushka's Avatar
Member with 51 posts.
 
Join Date: Sep 2004
Experience: much to learn
11-Feb-2005, 06:15 AM #4
I thought i was doing something stupid. wood for the trees
cheers
ben
mushka's Avatar
Member with 51 posts.
 
Join Date: Sep 2004
Experience: much to learn
11-Feb-2005, 07:10 AM #5
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
Squashman's Avatar
Trusted Advisor with 18,705 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
Experience: Bocks of Rox
11-Feb-2005, 02:33 PM #6
Quote:
Originally Posted by mushka
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
Isn't that what I said in my first post.
mushka's Avatar
Member with 51 posts.
 
Join Date: Sep 2004
Experience: much to learn
11-Feb-2005, 02:49 PM #7
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
Reply

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.
Thread Tools



Facebook Facebook Twitter Twitter TechGuy.tv TechGuy.tv Mobile TSG Mobile
You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 07:06 AM.
Copyright © 1996 - 2011 TechGuy, Inc. All rights reserved.

Powered by Cermak Technologies, Inc.