Crontab command substitution problem


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Crontab command substitution problem
# 8  
Old 12-23-2009
cron doesn't care whether you're connected locally or from somewhere else, because it's primary design goal since it's creation was to run programs without any user interaction. That means no TTYs, no X displays by default, so it has no way of knowing what display you're running an X server at. You'll have to tell it that yourself, by whatever means (eg. writing the required DISPLAY variable to a file & reading that in your script)

As for substitution: no, cron doesn't know anything about that, because the shell can handle it just fine. The whole command you specify is passed, without any interpolation, to a shell, which then has to handle parameter & command expansion. Example: the line
Code:
* * * * * echo "$(date +'\%Y\%m\%dT\%H:\%M:\%S')" > /tmp/file

generates this file:
Code:
> cat /tmp/file
20091223T14:10:01

and this entry in the syslog
Code:
/usr/sbin/cron[11903]: (pludi) CMD (echo "$(date +'%Y%m%dT%H:%M:%S')" > /tmp/file)

You see, an expansion is done, just not by cron but by the shell it calls.
# 9  
Old 12-23-2009
To find out the environment variables which are set when a job starts in the default shell for cron, create a one-off cron containing just an "env" command. The output from "env" will be in the mail for the user who owns the cron.

We're still not clear what you are trying to achieve but using "cron" (which is a background task scheduler) to try to start a process which needs a foreground terminal is unlikely to be satisfactory.
# 10  
Old 12-23-2009
what you really want to do ( for best maintenance practices ) is not clutter up cron with a host of crazy commands.

Put all those crazy commands in a script somewhere, where you'll have control to debug at will. IE:

Code:
crontab file:

* * * * * /bin/ksh /home/quirkasaurus/bin/cron_env.sh /home/quirkasaurus/bin/rule_the_world.sh

Then my cron_env.sh sets up my full required environment,
and runs my script exactly in an environment I control completely, and not at the whims of however cron kicks things off.

My cron_env.sh is essentially:
Code:
. /home/quirkasaurus/.profile
$*

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Variable substitution problem

HI i was studying about variable substitution. below are info which was given in a online tutorial. ${parameter:-word}---> If parameter is null or unset, word is substituted for parameter. The value of parameter does not change. ${parameter:=word}---> If parameter is null or... (3 Replies)
Discussion started by: scriptor
3 Replies

2. Shell Programming and Scripting

Problem with running the "autorep" command via crontab

Hi, The user "MadeInGermany" tried to help on the below post by saying "This has been asked before; see the links below. Get your current LD_LIBRARY_PATH and redefine that in your ksh script! " Thanks for the help. but this did not help. And my post got locked. I can't reply on my previous... (5 Replies)
Discussion started by: girish1428
5 Replies

3. Shell Programming and Scripting

Another substitution problem

Hello again, I'm trying to change the following line: INSERT INTO PH1_TX_LOAD VALUES ('TX-78731-AABSS:4182-4','RH: GUIDE TO TENNIS',TO_DATE('18-JUN-2001:00:00:00', 'DD-MON-YYYY:HH24:MI:SS'),TO_DATE('21-JUN-2001:00:00:00', 'DD-MON-YYYY:HH24:MI:SS'),500) so that any TO_DATE is taken... (6 Replies)
Discussion started by: user_invalid
6 Replies

4. UNIX for Dummies Questions & Answers

read command - using output from command substitution

Hey, guys! Trying to research this is such a pain since the read command itself is a common word. Try searching "unix OR linux read command examples" or using the command substitution keyword. :eek: So, I wanted to use a command statement similar to the following. This is kinda taken... (2 Replies)
Discussion started by: ProGrammar
2 Replies

5. UNIX for Dummies Questions & Answers

sed insert command and variable expansion/command substitution

I know this script is crummy, but I was just messing around.. how do I get sed's insert command to allow variable expansion to show the filename? #!/bin/bash filename=`echo $0` /usr/bin/sed '/#include/ { i\ the filename is `$filename` }' $1 exit 0 (8 Replies)
Discussion started by: glev2005
8 Replies

6. Shell Programming and Scripting

sed substitution problem

Can anyone please help me on this. i have a file with lines say X X3200 X X X X2400 X X4100 I want to use sed to put the numbers in braces. the output should be like, X X(3200) X X X X(2400) X X(4100) (7 Replies)
Discussion started by: diliphp
7 Replies

7. Shell Programming and Scripting

problem in embeded command substitution

$ echo $(tty|sed 's#/*/##') pts/0 $ who | grep $(tty|sed 's#/*/##') grep: 0652-033 Cannot open 0551-011. grep: 0652-033 Cannot open Standard. grep: 0652-033 Cannot open input. grep: 0652-033 Cannot open is. grep: 0652-033 Cannot open not. grep: 0652-033 Cannot open a. grep: 0652-033 Cannot... (2 Replies)
Discussion started by: wrl
2 Replies

8. AIX

VI Substitution problem

I'm having a problem getting my variables to work in dishing out an RMC script. The $1 works fine. $2 does not Here's a portion of the script: server=$1 filesystem1=$2 # dsh -w $1 'mkcondition -c "/var space used" -s "Name == \"$2\"" -e "PercentTotUsed > 90" -d "An event will be generated... (7 Replies)
Discussion started by: gravy26
7 Replies

9. Shell Programming and Scripting

Substitution problem.

Hi, Just need some help in this. Suppose there is one file a.txt, which contains this data: "25187","00000022","00",28-MAR-2007,"" ,"D",-000001550,+0000000000,"C", ,+000000000,+000000000,000000000,"2","" ,29-MAR-2007 613TB.STEXTRF1 "25187","0000004H","00",29-MAR-2007,""... (3 Replies)
Discussion started by: er_ashu
3 Replies

10. UNIX for Dummies Questions & Answers

Having Problem with crontab command

Hi all , When i am tryting to execute crontab from home directory for a shell script which is located in some directory it is giving a error message The crontab file is 0 9-17 * * 1-5 /mydir/myshell The following output is given Your "cron" job /mydir/myshell produced the following... (1 Reply)
Discussion started by: arunava_maity
1 Replies
Login or Register to Ask a Question