Solved

how to put the command-line parameters in cron in Red-head Linux

Posted on 2010-09-19
4
519 Views
Last Modified: 2013-12-21
Would like to input some command-line parameters with cron on Linux (Red head).
Here is the test code:

test.sh
#! /bin/ksh
if [[ $# != 3 ]]; then
  echo "Wrong inputs"
  exit 0
fi

if [[ "$3" == "v" ]]; then
echo "$1 $2"
elif [[ "$3" == "tst" ]]; then
echo "$1 $2 $3"
else
 echo "Wrong info"
fi

If it is run in command-line prompt, it gets the right result:
/u02/test.sh Hello World tst > /tmp/test.log

In test.log
Hello World tst

However,
32 13 * * * /u02f/test.sh Hello World tst > /tmp/test.log 2 >&1

It gave in test.log

Wrong inputs

Gurus, please help.
0
Comment
Question by:jl66
4 Comments
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 300 total points
ID: 33712107
Hi,

the script worked on the command line because you didn't add the last (erroneous) part (2 >&1) there!

You must remove the space between "2" and ">&1"
else the "2" will be considered a parameter by the shell, raising $# to "4"

32 13 * * * /u02f/test.sh Hello World tst >/tmp/test.log 2>&1

It's also good practice (although not mandatory) not to leave a space between ">" and the following path.

That's all.



0
 
LVL 11

Assisted Solution

by:jgiordano
jgiordano earned 50 total points
ID: 33712110
if this is the exact cron entry then you have a typo in the file path; there is an f in your cron path and non in the first example.

32 13 * * * /u02f/test.sh Hello World tst


/u02/test.sh Hello World tst > /tmp/test.log
0
 
LVL 6

Assisted Solution

by:jghelfman40
jghelfman40 earned 150 total points
ID: 33735034
You may want to put your command in parantheticals, as you are then guaranteed that it will be interpreted as one command.
In addition to this you can run it against 'atd' as a test. If your atd isn't running it should be a startup script under /etc/init.d/

at now +1
> /u02f/test.sh Hello World tst >/tmp/test.log 2>&1

If this works then add it to cron:
32 13 * * * ( u02f/test.sh Hello World tst >/tmp/test.log 2>&1 )
0
 

Author Closing Comment

by:jl66
ID: 33784352
Thank each of you very much. It works. Sorry for delay.
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now