Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2010-09-19
4
Medium Priority
?
545 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 1200 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 200 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 600 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses

722 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