LinuxQuestions.org
Visit Jeremy's Blog.
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 09-29-2012, 06:06 PM   #1
miguelangeljma
LQ Newbie
 
Registered: Sep 2012
Posts: 9

Rep: Reputation: Disabled
Crontab is not working properly on CentOS 6.3


Hello, I am trying to schedule to run a script I made using Crontab. The problem is that although I use the right syntax of the command, it is doing NOTHING, and it is getting very annoying.

All i want is the script to run in a new terminal window. When i run the script manually it works perfect. What i am doing is the following:

crontab -e

*/1 * * * * bash /home/user/Script.sh

I also added the dir /home/user to the PATH so i can just write Script.sh to run the script. nothing has worked so far, not even the "at" Command.

Please help me, i'm new using Linux and got tired of the "Crash-Stress-meter" of Windows, thanks in advance.
 
Old 09-29-2012, 07:45 PM   #2
KinnowGrower
Member
 
Registered: May 2008
Location: Toronto
Distribution: Centos && Debian
Posts: 347

Rep: Reputation: 34
Quote:
Originally Posted by miguelangeljma View Post
*/1 * * * * bash /home/user/Script.sh
you can try to replace "bash" with root if script is supposed to run as root. I think bash is not a right option. Also not that S is capital in name of script.sh. I am assuming that is correct

Last edited by KinnowGrower; 09-29-2012 at 07:46 PM.
 
Old 09-30-2012, 01:00 AM   #3
miguelangeljma
LQ Newbie
 
Registered: Sep 2012
Posts: 9

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by KinnowGrower View Post
you can try to replace "bash" with root if script is supposed to run as root. I think bash is not a right option. Also not that S is capital in name of script.sh. I am assuming that is correct
It is not supposed to run as root, i am just testing the command to then apply it to automatic backups etc. Yes, the name of the script file is on capital S "Script.sh".
 
Old 09-30-2012, 02:00 AM   #4
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,258

Rep: Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947
* Remove the bash in the call, and add a #!/bin/bash to the top of the script if that's what it's supposed to run in.

* Make sure there's a blank line in the crontab after the command you plan to run

* Your PATH makes no difference in commands running through cron, as they don't source your .bashrc or .bash_profile. Cron's PATH is and will always be very limited, so make sure to reference the full path to any commands you call in the script

* Run your script with > /home/user/script.out 2>&1 at the end so you can see the output of the script, IE:
Code:
*/1 * * * * /home/user/Script.sh > /home/user/script.out 2>&1
* Post the contents of Script.sh

Last edited by suicidaleggroll; 09-30-2012 at 02:01 AM.
 
Old 09-30-2012, 10:54 AM   #5
miguelangeljma
LQ Newbie
 
Registered: Sep 2012
Posts: 9

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by suicidaleggroll View Post
* Remove the bash in the call, and add a #!/bin/bash to the top of the script if that's what it's supposed to run in.

* Make sure there's a blank line in the crontab after the command you plan to run

* Your PATH makes no difference in commands running through cron, as they don't source your .bashrc or .bash_profile. Cron's PATH is and will always be very limited, so make sure to reference the full path to any commands you call in the script

* Run your script with > /home/user/script.out 2>&1 at the end so you can see the output of the script, IE:
Code:
*/1 * * * * /home/user/Script.sh > /home/user/script.out 2>&1
* Post the contents of Script.sh
Hello, i made a video of what i'm doing so you can tell me what i'm doing wrong, Hope my bad english is understandable and the video shows everything you guys need to help me out. Thanks again for your efforts.

This is the link of the video http://www.youtube.com/watch?v=9LiTR...ature=youtu.be
 
Old 09-30-2012, 11:00 AM   #6
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,527

Rep: Reputation: 898Reputation: 898Reputation: 898Reputation: 898Reputation: 898Reputation: 898Reputation: 898
Is the cron daemon running?
Create a simple script, to see if that works.
Post the content of Script.sh

Kind regards
 
Old 09-30-2012, 11:22 AM   #7
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,331
Blog Entries: 55

Rep: Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530
...additionally
Quote:
Originally Posted by miguelangeljma View Post
All i want is the script to run in a new terminal window.
cron jobs are usually meant to perform some automated task requiring no user input or access to the desktop, so if your cron job is supposed to launch some GUI tool then you might have to explicitly export the DISPLAY variable in your script. Also note that if the cron daemon is running and unless you explicitly unset the MAILTO variable, any error messages will by default be sent to the crontab owner so check your local mailbox too.
 
Old 09-30-2012, 12:14 PM   #8
miguelangeljma
LQ Newbie
 
Registered: Sep 2012
Posts: 9

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by unSpawn View Post
...additionally

cron jobs are usually meant to perform some automated task requiring no user input or access to the desktop, so if your cron job is supposed to launch some GUI tool then you might have to explicitly export the DISPLAY variable in your script. Also note that if the cron daemon is running and unless you explicitly unset the MAILTO variable, any error messages will by default be sent to the crontab owner so check your local mailbox too.
i tested scheduling crontab to ping www.google.com to see if it was performing that action at the time i set it up, IT WAS so crontab is working, but not the way i need.

I am very sorry for being such a pain in the a** but i need to ask, how do i export the display in my script, so that when crontab executes my script it will pop up a new terminal window with the content of the script on it (allowing the user to interact with the executed script)?

Thanks in advance
 
Old 09-30-2012, 12:50 PM   #9
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,331
Blog Entries: 55

Rep: Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530
Since you haven't been methodical about things and haven't answered all questions in this thread (which you should have)

as root please run:
Code:
/sbin/service crond status
rpm -qa|grep -i cron
That way we can see if which cron(-related) SW is installed and if the cron daemon is running.

Now as unprivileged user (your own account) please run:
Code:
crontab -l
cat /home/user/Script.sh
 
Old 09-30-2012, 03:48 PM   #10
miguelangeljma
LQ Newbie
 
Registered: Sep 2012
Posts: 9

Original Poster
Rep: Reputation: Disabled
Code:
[Miguel@Miguel Desktop]$ su -
Password: 
[root@Miguel ~]# /sbin/service crond status
crond (pid  2613) is running...
[root@Miguel ~]# exit
logout
I deleted the cron jobs i previously had, now I know that cron is working fine.

Code:
[Miguel@Miguel Desktop]$ crontab -l
no crontab for Miguel
And this is the script i am trying to execute in a new terminal window (xterm terminal window) using crontab or any other tool that can perform what i want.

Code:
[Miguel@Miguel Desktop]$ cat /home/Miguel/Script_Calculadora.sh 
#!/bin/bash
 
export DISPLAY=:0.0
clear
opcion=400
while [ $opcion -ne 5 ]
do

echo "Bienvenidos a la calculadora basica, por favor elija una opcion "
echo "1.Suma"
echo "2.Resta"
echo "3.Multiplicacion"
echo "4.Division"
echo "5.Salir"

echo "Introduce una opcion "
read opcion
case $opcion in

1) echo "Introduce el primer numero "
read a
echo "Introduce el segundo numero "
read b
echo "El resultado es '$(( $a + $b ))'" ;;

2) echo "Introduce el primer numero "
read a
echo "Introduce el segundo numero "
read b
echo "El resultado es '$(( $a - $b ))'" ;;

3) echo "Introduce el primer numero "
read a
echo "Introduce el segundo numero "
read b
echo "El resultado es '$(( $a * $b ))'" ;;

4) echo "Introduce el primer numero "
read a
echo "Introduce el segundo numero "
read b
echo "El resultado es '$(( $a / $b ))'" ;;
esac
done
 
Old 09-30-2012, 04:47 PM   #11
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,331
Blog Entries: 55

Rep: Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530
Like I said before cron jobs are meant to perform automated tasks requiring no user input or access to the desktop. In your case exporting the DISPLAY variable has to be done as crond executes the job. Here is an example cron job that will fire (as long as the env and zenity binaries are available, in the path cron knows about and there is actually a display running at ":0.0") each day at 9 PM:
Code:
0 21 * * * env DISPLAY=":0.0" zenity --title "Ta-daa" --info --text "Hello World\!"
 
Old 09-30-2012, 11:25 PM   #12
miguelangeljma
LQ Newbie
 
Registered: Sep 2012
Posts: 9

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by unSpawn View Post
Like I said before cron jobs are meant to perform automated tasks requiring no user input or access to the desktop. In your case exporting the DISPLAY variable has to be done as crond executes the job. Here is an example cron job that will fire (as long as the env and zenity binaries are available, in the path cron knows about and there is actually a display running at ":0.0") each day at 9 PM:
Code:
0 21 * * * env DISPLAY=":0.0" zenity --title "Ta-daa" --info --text "Hello World\!"
Thanks, this example was very helpful, now i understand that crontab won't give me any user interaction pop-up.

I was testing with the zenity command along with the xdg-open command to open my script and it is kinda working, but instead of opening my script on a new terminal window it was opening it on a text editor software.

Since it is not completely related to the main thread (Crontab is not working) we can close it, unless you can give me an answer to my 2nd question before closing it. What i need is to open a script as an executable file from the command line, i want it to be executed the same way i run it from the command line, but in a different command line.
 
Old 09-30-2012, 11:56 PM   #13
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Try something like this, maybe?

Code:
55  16  * * * DISPLAY=:0.0 xterm -e "/home/Miguel/Script_Calculadora.sh"
 
  


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
[SOLVED] How to properly configure mail server on CentOS 6.3? Vita Linux - Software 1 08-16-2012 08:46 AM
[SOLVED] Centos 6 Crontab NOT runing Ubunter Linux - Server 16 04-30-2012 08:45 AM
CentOS - Can't get VNC to display properly Anthonys Linux - Newbie 2 07-30-2008 05:01 AM
script won't run in crontab(centos 5) ncsuapex Programming 2 03-09-2008 07:55 PM
Centos OS not loading properly elkikz Linux - Laptop and Netbook 4 09-19-2006 05:06 PM


All times are GMT -5. The time now is 10:29 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