LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-26-2012, 11:26 PM   #1
slowerogue
Member
 
Registered: Oct 2012
Posts: 93

Rep: Reputation: Disabled
script wont run from cront


Hi guys,
i made a script file at /tmp/scripts/autoarchive.sh
the sh can be run using ./autoarchive.sh

then i make a file "auto"
Code:
#!/bin/sh
*/1 * * * * /bin/echo "hehe" >> /txt
*/2 * * * * /tmp/scripts/autoarchive.sh

then i run crontab auto
then i cat /txt
Code:
[root@liang ~]# cat /txt
hehe
hehe
echo hehe run sucessfully, but it wont run the autoarchive.sh
it shouldnt be the scripts file's issue, as i was able to run it manually without error

plz help

Last edited by slowerogue; 12-26-2012 at 11:28 PM.
 
Old 12-27-2012, 12:26 AM   #2
Rupadhya
Member
 
Registered: Sep 2012
Location: Hoffman Estates, IL
Distribution: Fedora 20
Posts: 167

Rep: Reputation: Disabled
Can you run autoarchive.sh from root?
Code:
$ su -
Password: 
# cd /tmp/scripts
# ./autoarchive.sh
 
Old 12-27-2012, 07:09 AM   #3
slowerogue
Member
 
Registered: Oct 2012
Posts: 93

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Rupadhya View Post
Can you run autoarchive.sh from root?
Code:
$ su -
Password: 
# cd /tmp/scripts
# ./autoarchive.sh
can
 
Old 12-27-2012, 07:59 AM   #4
Rupadhya
Member
 
Registered: Sep 2012
Location: Hoffman Estates, IL
Distribution: Fedora 20
Posts: 167

Rep: Reputation: Disabled
Can you try
Code:
sh -xvv ./autoarchive.sh
and capture the output, and post it here? I am kind of dumbfounded..

Thanks..

Raj
 
Old 12-27-2012, 10:23 AM   #5
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,027

Rep: Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845
can you show us the output of:
Code:
crontab -l
also, cron doesnt run in a shell so system variables (such as $PATH) arent set so you should use absolute paths in your script.

Last edited by schneidz; 12-27-2012 at 10:25 AM.
 
Old 12-30-2012, 08:43 PM   #6
slowerogue
Member
 
Registered: Oct 2012
Posts: 93

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Rupadhya View Post
Can you try
Code:
sh -xvv ./autoarchive.sh
and capture the output, and post it here? I am kind of dumbfounded..

Thanks..

Raj
# sh -xxv ./autoarchive.sh
module () { eval `/usr/bin/modulecmd bash $*`
}
#!/bin/bash
date=`date "+%y-%b-%d..%T"`
date "+%y-%b-%d..%T"
++ date +%y-%b-%d..%T
+ date=12-Dec-27..14:09:31
echo "$date"
+ echo 12-Dec-27..14:09:31
12-Dec-27..14:09:31
tar -cvzf /archive/$date.ftparchive.tar.gz /ftpdata/
+ tar -cvzf /archive/12-Dec-27..14:09:31.ftparchive.tar.gz /ftpdata/
tar: Removing leading `/' from member names
/ftpdata/
/ftpdata/file1
/ftpdata/dir1/
/ftpdata/dir1/a2
/ftpdata/dir1/a1
/ftpdata/dir1/a4
/ftpdata/dir1/a3
/ftpdata/file2
/ftpdata/dir2/
/ftpdata/dir2/b4
/ftpdata/dir2/b2
/ftpdata/dir2/b1
/ftpdata/dir2/b3
/ftpdata/file4
/ftpdata/dir4/
/ftpdata/dir4/d3
/ftpdata/dir4/d2
/ftpdata/dir4/d4
/ftpdata/dir4/d1
/ftpdata/file3
/ftpdata/dir3/
/ftpdata/dir3/c3
/ftpdata/dir3/c2
/ftpdata/dir3/c1
/ftpdata/dir3/c4
[root@liang scripts]#

---------- Post added 12-31-12 at 09:44 AM ----------

Quote:
Originally Posted by schneidz View Post
can you show us the output of:
Code:
crontab -l
also, cron doesnt run in a shell so system variables (such as $PATH) arent set so you should use absolute paths in your script.
[root@liang scripts]# crontab -l
#!/bin/sh

*/1 * * * * root /bin/echo "hehe" >> /txt
*/2 * * * * root /tmp/scripts/autoarchive.sh
 
Old 12-30-2012, 09:27 PM   #7
Rupadhya
Member
 
Registered: Sep 2012
Location: Hoffman Estates, IL
Distribution: Fedora 20
Posts: 167

Rep: Reputation: Disabled
Hmmm. Still dumbfounded...

Let's try this...


Code:
$ su -
Password: 
# date   # To get the current time
Sun Dec 30 20:21:44 CST 2012
# crontab -e
{Change your autoarchive.sh to a few minutes in the future.}
:wq!
Wait until the time elapses....
Check your root's email and if the tar file is created.... Maybe it is something about your cron job startup parms......

Just a guess. The script file looks good to me.

- Raj
 
Old 12-30-2012, 10:16 PM   #8
slowerogue
Member
 
Registered: Oct 2012
Posts: 93

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Rupadhya View Post
Hmmm. Still dumbfounded...

Let's try this...


Code:
$ su -
Password: 
# date   # To get the current time
Sun Dec 30 20:21:44 CST 2012
# crontab -e
{Change your autoarchive.sh to a few minutes in the future.}
:wq!
Wait until the time elapses....
Check your root's email and if the tar file is created.... Maybe it is something about your cron job startup parms......

Just a guess. The script file looks good to me.

- Raj
hi, my redhat run from vmware..the date was wrong everytime i hibernate my computer ,b
ut i set ntp,so it took a few minutes to sync the time.

now it is already sync and i have set it two minute later.
still them same ><
 
Old 12-30-2012, 10:36 PM   #9
slowerogue
Member
 
Registered: Oct 2012
Posts: 93

Original Poster
Rep: Reputation: Disabled
lol... it is the root problem
the mail says: root command not found
i remove the root
just 35 11 * * * /tmp/scripts/autoarchive. then it works

thanks for your help anyway
 
Old 12-30-2012, 10:49 PM   #10
Rupadhya
Member
 
Registered: Sep 2012
Location: Hoffman Estates, IL
Distribution: Fedora 20
Posts: 167

Rep: Reputation: Disabled
Yay! I am glad you figured it out...

- Raj
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
.forward file script wont run after moving to centos 6.2 and sendmail 8.14 cxc718 Linux - Server 2 07-24-2012 12:12 PM
[SOLVED] Problems with rc.local, it wont run my bash-script at startup ScorchPipe Linux - Software 10 01-10-2011 04:41 PM
[SOLVED] Perl script wont run - no error, no nothing (this *should* be easy!) Sly Phy Programming 1 08-08-2010 02:41 PM
Cron wont run my shell script shelb Linux - Desktop 4 05-27-2007 10:55 PM
My script wont run on boot Unicron Ubuntu 2 06-18-2006 12:19 PM


All times are GMT -5. The time now is 12:48 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration