LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 01-30-2009, 01:15 PM   #1
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,196

Rep: Reputation: 1044Reputation: 1044Reputation: 1044Reputation: 1044Reputation: 1044Reputation: 1044Reputation: 1044Reputation: 1044
Use a pipe in a cron command?


I have set up a cron job in /etc/crontab.

The line looks like this:
Code:
02 * * * *      root    /bin/echo "update process_control set log_level='INFO' where name ='TransmitterController TH1'" | /usr/bin/mysql -uphp -pmypasswd event_reports_dev
What I see in /var/log/syslog is this:
Code:
/bin/echo "update process_control set log_level='INFO' where name ='TransmitterController TH1'" | /usr/bin/mysql -uphp -pmypasswd event_reports_dev
That is the command line exactly as I want it.

However, the requested setting is not performed with mysql. When I enter the command on the command line, it is set, so my syntax should be correct.

I know that piping creates a different process, different subshell, but I don't see an apparent reason why I should not be allowed to do this in a cron job. I create a string, echo it, pipe it, another shell gets started, mysql is called and the string is piped from one shell to the other.

Anyway, I put the whole command line including pipe in a script file, and call the script file from cron. It works perfectly.

Somehow I don't seem to understand what it going on in cron.

jlinkels
 
Old 01-30-2009, 01:59 PM   #2
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Hi -

It's probably permissions - the script is running in the context of a user who's authorized to use mysql; the failing cron job isn't.

'Hope that helps .. PSM
 
Old 01-30-2009, 02:44 PM   #3
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
Most implementations of cron do not start a shell with the process in it, and a shell is what would parse out the pipe and run the two processes separately. Echo is seeing the pipe and mysql command as part of its arguments, nothing more. You should be able to do what you'd like by placing the commands in a bash script and calling it from cron, or by using the the -c option to bash, but be careful of your quoting then!
 
Old 01-30-2009, 02:57 PM   #4
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,196

Original Poster
Rep: Reputation: 1044Reputation: 1044Reputation: 1044Reputation: 1044Reputation: 1044Reputation: 1044Reputation: 1044Reputation: 1044
Quote:
Originally Posted by paulsm4 View Post
It's probably permissions - the script is running in the context of a user who's authorized to use mysql;
Not likely, I am running the command as root, and I give MySQL username and password on the command line.

Quote:
Originally Posted by matir
Most implementations of cron do not start a shell with the process in it, and a shell is what would parse out the pipe and run the two processes separately.
That must be it. I knew pipes were dangerous, and this is a good explanation.

Quote:
Originally Posted by matir
You should be able to do what you'd like by placing the commands in a bash script and calling it from cron
Quote:
Originally Posted by jlinkels
Anyway, I put the whole command line including pipe in a script file, and call the script file from cron. It works perfectly.
That is what I did, and it works, I just couldn't understand why I didn't work with the pipe. I hope someone else finds the post

jlinkels
 
1 members found this post helpful.
  


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
Pipe output of command to php !!! ALInux Programming 7 12-30-2006 01:36 PM
kill command in a pipe bujecas Linux - General 1 02-02-2006 08:55 AM
how to pipe and parse output of a command learnfast Linux - Newbie 2 06-15-2005 05:55 AM
how to: a pipe command? youngstorm Linux - Newbie 2 02-02-2005 11:52 AM
Pipe command question satimis Linux - Newbie 8 01-07-2004 11:54 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

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