Mourning the loss of our friend, WhitPhil.
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 audio black screen blue screen boot bsod connection crash dell desktop driver drivers dvd email error excel firefox hard drive hardware hijackthis internet keyboard laptop malware monitor motherboard network networking outlook problem processor recovery router safe mode screen slow sound spyware tdlwsp.dll trojan upgrade video virus vista vundo windows windows 7 windows vista windows xp wireless
Search
Search for:
Tech Support Guy Forums > Operating Systems > Linux and Unix >
need help with my cron script

Tip: Click here to scan for System Errors and Optimize PC performance
[ Sponsored Link ]

Closed Thread
 
Thread Tools
mushka's Avatar
Member with 51 posts.
 
Join Date: Sep 2004
Experience: much to learn
10-Feb-2005, 08: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
Distinguished Member with 14,989 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
Experience: IIAHYAYCESA,YAADA!
10-Feb-2005, 10: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.
__________________
I hate asking the same question twice!
How to ask questions the smart way!
Microsoft MVP - User Desktop Experience

Last edited by LwdSquashman : 10-Feb-2005 10:48 AM.
Squashman's Avatar
Distinguished Member with 14,989 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
Experience: IIAHYAYCESA,YAADA!
10-Feb-2005, 10: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, 05: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, 06: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
Distinguished Member with 14,989 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
Experience: IIAHYAYCESA,YAADA!
11-Feb-2005, 01: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, 01: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
Closed Thread Bookmark and Share

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.

Smart Search

Find your solution!



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


You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -5. The time now is 01:51 PM.
Copyright © 1996 - 2009 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.
Powered by Cermak Technologies, Inc.