LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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, 10:26 PM   #1
slowerogue
Member
 
Registered: Oct 2012
Posts: 96

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 10:28 PM.
 
Old 12-26-2012, 11:26 PM   #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, 06:09 AM   #3
slowerogue
Member
 
Registered: Oct 2012
Posts: 96

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, 06: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, 09:23 AM   #5
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
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 09:25 AM.
 
Old 12-30-2012, 07:43 PM   #6
slowerogue
Member
 
Registered: Oct 2012
Posts: 96

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, 08: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, 09:16 PM   #8
slowerogue
Member
 
Registered: Oct 2012
Posts: 96

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, 09:36 PM   #9
slowerogue
Member
 
Registered: Oct 2012
Posts: 96

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, 09: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



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 11:12 AM
[SOLVED] Problems with rc.local, it wont run my bash-script at startup ScorchPipe Linux - Software 10 01-10-2011 03:41 PM
[SOLVED] Perl script wont run - no error, no nothing (this *should* be easy!) Sly Phy Programming 1 08-08-2010 01:41 PM
Cron wont run my shell script shelb Linux - Desktop 4 05-27-2007 09:55 PM
My script wont run on boot Unicron Ubuntu 2 06-18-2006 11:19 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10: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
Open Source Consulting | Domain Registration