Crontab and interactive script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Crontab and interactive script
# 8  
Old 06-28-2011
Following your steps I get no prompt at all, it just print the output.

swmml works like perl (it is a perl script): if you want to execute "on the fly" command in perl you write:
Code:
perl -e "print \"Hello world\n\""

I used the word "interactive" because if I execute swmml by its own it enters a shell like the following:
Code:
-bash-3.00$ swmml

+---------+    Signalware Enhanced Terminal Handler v9.41.1
|  swmml  |    Copyright 1993-2011 Ulticom, Inc.
+---------+    All Rights Reserved

Welcome to swmml. To get some help, type 'man'.
Current editing mode set to: emacs mode.

blahblah:hostname:225 >

Thanks!
# 9  
Old 06-28-2011
What are you trying to achieve ?
Before scripting something you must ensure that the intermediate commande give the intended result.

Example if you want a script toto.sh that display your hostnae and full id
after having check that
Code:
hostname

and
Code:
id

give the result you need you can just

Code:
echo "I am connected to : $(hostname)"
echo "My ID is : $(id)"

Now if you intend to get output from some swmml command, you first have to ensure that when you run it manually it generate the expected output, you will then be able to start coding the handling of the output according to your needs.

To far if you just want "Hello World" to be Displayed :

Code:
echo "Hello World"

would do the work
# 10  
Old 06-28-2011
Code:
 perldoc -f -X

Remove the checks for char special and run it, the check was there for a reason, so you'll have to see what breaks and work around it.
# 11  
Old 06-28-2011
Dear all,
it seems that today I can't explain myself very well.
Please forgive me and let me try one last time.
I'll try to start from the beginning:

#1
I need to retrieve some information with the following script:
Code:
swmml_D_PROCESS.sh
#!/usr/bin/bash
su - omniusr -c "swmml -e 'DISPLAY-PROCESS'" | /usr/bin/awk -F" " '{if ( $11 ==  "TRUE" || $11 == "FALSE" ) print $11,$3,$1}' > /tmp/swmml_D_PROCESS.tmp
chmod 777 /tmp/swmml_D_PROCESS.tmp

If I execute the script from command line (root user) it works fine and outputs something like the following:
Quote:
FALSE hostname SWCTRL
TRUE hostname iwf_SCMG
TRUE hostname iwf_TCMG
TRUE hostname iwf
FALSE hostname SWCTRL
#2
Now I want to launch the swmml_D_PROCESS.sh script in root's crontab:
Code:
15 * * * * /scripts/swmml_D_PROCESS.sh > /scripts/swmml_D_PROCESS.log 2>&1

#3
All I get from the above is the following swmml_D_PROCESS.log:
Quote:
ERROR: STDIN is a character special file
instead of the expected output (#1).

#4
Since the above didn't work I tryed to reduce at minimum the commands being executed, this lead to the "su - omniusr ...." in crontab, but no success.

#5
I tryed one more thing in crontab:
Code:
15 * * * * . /etc/profile; /scripts/swmml_D_PROCESS.sh > /scripts/swmml_D_PROCESS.log 2>&1

But nothing changed.

Please, let me know if I miss some informations.

Thanks to all of you for helping me Smilie

---------- Post updated at 04:30 PM ---------- Previous update was at 04:29 PM ----------

Bravo Skrynesaver!

Now that we made one step forward can anybody explain why if I launch the script from command line it works while if I put it in crontab it doesn't work?

Maybe something is missing from the crontab environment?

I cannot figure it out.

Thanks Skrynesaver!!!
# 12  
Old 06-28-2011
What's missing is a terminal Smilie
STDIN and STDOUT are character devices rather than ttys when called from cron.

If you modify the script to remove the check it will probably break somewhere else (I don't know the script at all) however it may be possible to isolate where it breaks and resolve the issue using the Expect module or similar, however that may be a complex Perl coding issue
# 13  
Old 06-28-2011
The reason few won't work from CRON but from command line is due to non availability of it's environment from CRON. The same problem I found is with sqlplus which works OK from command line but not from CRON.

For that I have to set my ORACLE_HOME and ORACLE_SID etc explicitly in the script I am executing from cron .

In your case ,
check if the "swmml" env is available to run from cron, if not set it before invoking it.
# 14  
Old 06-28-2011
Quote:
#3
All I get from the above is the following swmml_D_PROCESS.log:
ERROR: STDIN is a character special file
That is coming from your program. Did you try commenting out that code block because it clearly does not work when run from cron?

Quote:
#5
I tryed one more thing in crontab:
Code:
15 * * * * . /etc/profile; /scripts/swmml_D_PROCESS.sh > /scripts/swmml_D_PROCESS.log 2>&1
Your original version was better. This version runs the script as the wrong user and does not set the environment correctly.
The lines to choose the right Shell and then set up the environment need to be at the beginning of the script /scripts/swmml_D_PROCESS.sh if "su - username" gives trouble.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Interactive Shutdown script

Hello folks. I will start out by saying as far as unix/linux scripting goes I know less about it than i do about giving birth (I'm a guy hehe). I am looking to make a shutdown script that will either shut down the system or reboot it using one of the shutdown run methods IE init 2 - 5 or a base... (1 Reply)
Discussion started by: azurie
1 Replies

2. Shell Programming and Scripting

Interactive script with background

I have script, which need some variable from user and i use below command for this read this script works fine while running without background, but when i run this script in background, it ask first variable then immediately it show below error KSH variable not found please let me... (1 Reply)
Discussion started by: pallvi_mahajan
1 Replies

3. Shell Programming and Scripting

Non interactive su in bash script

Hi, I have a python gui which allow users entering the root password, then a bash script is called to run "su" with the root password on the background. I could find a way to run "su" with a password. How to run "su" in a bash script without password prompt? Thank you. (4 Replies)
Discussion started by: hce
4 Replies

4. Shell Programming and Scripting

Interactive script – if then

Hi, I am writing an interactive shell script (ksh) but I have no idea how I could make a condition on it : Variables : rep_config="${rep_tools}/_CONFIG" rep_config_old="${rep_config}/_PROTO_OLD" Here is the interactice part : lst_proto=$(cat... (2 Replies)
Discussion started by: Aswex
2 Replies

5. Shell Programming and Scripting

Interactive script

Greetings gurus I have this simple scripts #!/bin/bash find /kl1/CTT/TQI_001/330_spike/sz00/latcon1/ -type d -name "*.dig" > data_schema find /kl1/CTT/TQI_001/330_spike/sz00/latcon1/ -type d -name "*.dig" >> data_schema <data.schema awk '{print NR, "inVol=" $0, "setDt=4000",... (1 Reply)
Discussion started by: Marjan
1 Replies

6. Homework & Coursework Questions

How to write script that behaves both in interactive and non interactive mode

Q. Write a script that behaves both in interactive and non interactive mode. When no arguments are supplied it picks up each C program from the directory and prints first 10 lines. It then prompts for deletion of the file. If user supplies arguments with the script , then it works on those files... (8 Replies)
Discussion started by: rits
8 Replies

7. Homework & Coursework Questions

Help with Interactive / Non Interactive Shell script

Q. Write a script that behaves both in interactive and non interactive mode. When no arguments are supplied it picks up each C program from the directory and prints first 10 lines. It then prompts for deletion of the file. If user supplies arguments with the script , then it works on those files... (1 Reply)
Discussion started by: rits
1 Replies

8. Shell Programming and Scripting

Automating Interactive script

I have a script that will install software on all remote host. At the end of the script it starts the install.sh part and goes into a interactive mode asking Yes or No questions and prompting to add a username and password. My question is how can I script this so that these questions are... (7 Replies)
Discussion started by: soupbone38
7 Replies

9. Shell Programming and Scripting

script to non interactive mode

Gud morning everybody, I need small help form you people,Please advice me. I have a utility(adpatch) which takes 10-15 prompts, i want to automate this by calling this utility in shell script. Now my qiestion i want to run the script in non interactive mode. An example. $adpatch... (1 Reply)
Discussion started by: swetham.apps
1 Replies

10. Shell Programming and Scripting

Wrap Interactive Script

Does anyone know of a program to wrap an interactive script into an application..I tried using platypus but i want a utility to allow interactive scripts to be run in a stand-alone window to avoid .profile settings on multiple computers...platypus provides the option of a text window output but... (0 Replies)
Discussion started by: meskue
0 Replies
Login or Register to Ask a Question