Register
It is currently Fri Apr 18, 2014 11:26 am

Cannot get my script to run, keep returning an error.


All times are UTC - 6 hours


Post new topic Reply to topic  [ 6 posts ] 
Author Message
 PostPosted: Mon Apr 26, 2010 12:56 pm   

Joined: Mon Apr 26, 2010 12:16 pm
Posts: 2
Hello all,

This is the first script I have tried to write and is intended to go in my crontab to be run every sunday night. Basically it takes data from one partition that is over 31 day old and moves it to another partition. Before which it deletes anything over a 67 days old in the destination partition in order to free up space for the incoming data. Every command works in the terminal.

here is the script

Code:

#! /bin/bash -eu
echo "script started"

find /media/over30 -maxdepth 1 -mtime +67 -exec rm -R {} \;
echo "deleted anything over 67 days in secondary partition"

find /media/Backups -maxdepth 1 -mtime +31 -exec cp -R {} /media/over30 \;
echo "moved anything over 31 days in first partition"

find /media/Backups -maxdepth 1 -mtime +31 -exec rm -R {} \;
echo "deleted anything over 31 days in first partition"



When I run the scripts it returns with an error "command not found". Any ideas?


Last edited by jasoncarr on Tue Apr 27, 2010 8:44 am, edited 1 time in total.

Top
 Profile  
 PostPosted: Mon Apr 26, 2010 7:13 pm   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 512
did you write this script under *n?x , or w$ ?


Top
 Profile  
 PostPosted: Tue Apr 27, 2010 12:35 am   
User avatar

Joined: Sat Jun 13, 2009 8:53 pm
Posts: 73
Location: Texas!
Assuming it's in Linux, did you make the script executable and call it correctly? i.e.
Code:
> chmod u+x myscript.sh
> ./myscript.sh

- thobbs


Top
 Profile  
 PostPosted: Tue Apr 27, 2010 8:36 am   

Joined: Mon Apr 26, 2010 12:16 pm
Posts: 2
Thanks for the reply.

I am using Linux and I did set it to be executable and call it correctly. I suppose I should of also noted that the script gets far enough to echo the "scripted started" string before stopping. This leads me to believe that it is the first find command that is the problem but the command runs just fine in a terminal on its own so I don't understand why it would return an error in the script.

Here is exactly what is happening.
Code:

./backup.sh (as root)
script started
: command not found:



Top
 Profile  
 PostPosted: Mon May 03, 2010 1:32 am   
User avatar

Joined: Sat Jun 13, 2009 8:53 pm
Posts: 73
Location: Texas!
Hmm...

As root, run:
Code:
> which find

and see if it cannot find it. If it does not, do the same as your normal user and note the location. Then, as root,
Code:
> echo $PATH

and make sure that the list of directories includes the one where find is. If it does not include that directory, add it to PATH in the script:
Code:
PATH="$PATH:/path/to/find"


If that doesn't work, well... who knows.

- thobbs


Top
 Profile  
 PostPosted: Tue May 04, 2010 10:36 am   

Joined: Wed Apr 14, 2010 10:23 am
Posts: 17
Beside the fact that cron starts tasks with a well-defined PATH (see crontab.5), his pasted terminal output indicate a CRLF issue or similar, if I'm not mistaken.


Top
 Profile WWW  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 10 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP