Running external script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Running external script
# 1  
Old 07-31-2009
Error Running external script

I do have one script which needs to be run hourly and should generates a report using an "appadmin" user. But script locates in my home directory.

Whenerver i executes this script from my home directory /home/jg55555 it prompts me for the password, which is not required since im assinging the Value to the Variable . Please do check the script pasted below.

#!/usr/bin/ksh
#Login as Appadmin

LOGIN= 'Appadminl'
PASSWD= 'Blackt0p'
echo "Login as Appadmin"
su - $LOGIN
Password $ PASSWD
if [ echo$? -eq 0]
then
cd $HOME/
while [ true ]
do
hour=`date +%H`
minute=`date +%M`
second=`date +%S`
eid=Raghunandan.singh@mail.com
if [ $minute -eq 53 ] && [ $second -eq 30 ]
then
echo "Running this 'date +%H' Monitoring Script"
/home/appadmin/Metrics/lastHour.pl $eid
fi
sleep 1
done

And the error message im getting is:

./scheduleMonitoringScript.ksh[5]: =Appadmin: not found
./scheduleMonitoringScript.ksh[6]: =Blackt0p: not found
Login as Appadmin
Password:
su: Sorry
./scheduleMonitoringScript.ksh[9]: Password: not found


And am not able to reach the ~Appadmin instead in going to this path.

$ ./scheduleMonitoringScript.ksh
Login as Appadmin
Password:
Last successful login for prodcntl: Fri Jul 31 15:44:01 CST6CDT 2009
Last unsuccessful login for prodcntl: Wed Jul 29 14:33:15 CST6CDT 2009
jg355187 login on pts/7 at 15:44:03
plsh0745:/production/eks>^Z
logout
./scheduleMonitoringScript.ksh[9]: Blackt0p: not found
[3] + Stopped ./scheduleMonitoringScript.ksh


Could someone suggest me on this , how to make this script workable.

Thanks in Advance Smilie

BS
# 2  
Old 07-31-2009
You seem to have a space between $ and Password on this line: Password $ PASSWD. That may be causing it.
# 3  
Old 07-31-2009
Quote:
Originally Posted by raghunsi
Code:
while [ true ]


That works, but probably not for the reason you think it does. It is true because 'true' is a non-empty string; it doesn't run the command 'true'. For that, use:

Code:
while true
do

Quote:
Code:
do
hour=`date +%H`
minute=`date +%M`
second=`date +%S`


Not only is three calls to date inefficient, but it will give you the wrong results if a time boundary is passed between calls.

Use eval and a single date command:

Code:
eval "$( date "+hour=%H minute=%M second=%S")"

# 4  
Old 08-02-2009
Quote:
Originally Posted by cfajohnson
cfajohnson eval is nice
.
Also read is answer = run once and parse.
Generic version:
Code:
read h m s <<EOF
$(date '+%H %M %S')
EOF

Ksh can do also:
Code:
date '+%H %M %S' | read h m s

Array is also nice method, if you have list of values
Code:
values=(   $(date '+%H %M %S')  )
# ${values[0]} is 1st value
# ${#values[*]} number of values

# 5  
Old 08-06-2009
Running external script

Sorry for the late reply,.

But i dont have any issues related to Date parameters, its working fine for me .
The real problem is login to the server as Super User.

#Login as Appadmin

LOGIN= 'Appadminl'
PASSWD= 'Blackt0p'
echo "Login as Appadmin"
su - $LOGIN
Password $PASSWD
if [ echo$? -eq 0]

then

cd $HOME/


When i run this script from my home

pri04tp:home/jg5555>./scheduleMonitoringscript

It is prompting me to pass Loginname & Password , which it should NOT prompt me to do so , since i have provided values for both the variable parameter.

Below is the log that i captured from the server. The script is halting in the different location & as well as its prompting me to enter password maually.

$ ./scheduleMonitoringScript.ksh
Login as Appadmin
Password:
Last successful login for Appadmin: Thu Aug 6 03:59:01 CST6CDT 2009
Last unsuccessful login for Appadmin: Mon Aug 3 02:56:58 CST6CDT 2009
jg55555 login on pts/3 at 03:59:44
pri04tp:/production/tps>


But when I have to exit,.. this is how the script reacts.

pri04tp:/production/tps>^Z^C
pri04tp:/production/tps>
logout
[1] + Stopped ./scheduleMonitoringScript.ksh


I guess there is a bug in my script .. Please correct me if im going wrong.

Thanks in Advance
# 6  
Old 08-06-2009
To keep the forums high quality for all users, please take the time to format your posts correctly.

First of all, use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags [code] and [/code] by hand.)

Second, avoid adding color or different fonts and font size to your posts. Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.

Third, be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.

Thank You.

The UNIX and Linux Forums
# 7  
Old 08-06-2009
Put your script using CODE-blog using cut-paste, because your message not include working ksh script. Something like:
Code:
#!/bin/ksh
#Login as Appadmin

LOGIN='Appadminl'
PASSWD='Blackt0p'
echo "Login as $LOGIN"
su - $LOGIN
Password $PASSWD
if [  $? -eq 0  ]
then
    cd $HOME/
fi

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk - saving results of external script to variable.

So, I've been playing with speeding up some analysis we do by using multiple threads of awk (actually, mawk, but code-compatible as far as I use it) on multiple CPU cores. So, I have a big data file and I have several copies of exactly the same processor script, written in mawk. I also have a... (8 Replies)
Discussion started by: treesloth
8 Replies

2. Shell Programming and Scripting

How to run the Shell Script from external directory using java?

Hi, I have created a Shell Script and invoke through java using Process Builder It's working fine, if (Shell script file ) in the same directory as java file. By Problem: How to run the Shell Script file( resides in external directory) using java. What configuration i have... (1 Reply)
Discussion started by: nanthagopal
1 Replies

3. Shell Programming and Scripting

Running external programs inside an if then else

Good morning, First time poster. be gentle! :) I do not know coding all that well but I can hack the hell out of example scripts! I just cant wrap my brain around this one. Im trying to run two grep statements in the first IF statement and doing an AND between them. Something is going... (6 Replies)
Discussion started by: mrplow2k69
6 Replies

4. Web Development

cgi script and external UNIX commands (like swadm)

Hi, I am trying to implement a server monitoring dashboard using cgi scripting. I am planning to run the necessary unix scripts from the web page using cgi. This method works fine for standard unix commands but I am unable to run some external unix commands (like swadm show_processes, swadm... (9 Replies)
Discussion started by: jofinjoseph
9 Replies

5. Shell Programming and Scripting

passing arguments to external script

Hi! I have a python script that requires arguments and these arguments are file paths. This script works fine when executed like this: /my_python_script "file_path1" "file_path2" (i added quotes as some file names may have weird characters) the issue happens when i launch my python script... (14 Replies)
Discussion started by: gigagigosu
14 Replies

6. Shell Programming and Scripting

Getting category when given the variable from external file to shell script

Hi, I have a script that interacts with a config file in the format: file1.txt file2.txt file3.txt file4.txt file5.txt file6.txt I would like to return the Category, when given the file name. (11 Replies)
Discussion started by: MoreCowbell
11 Replies

7. Shell Programming and Scripting

importing functions from an external bash script

Hi all, I'm trying to import some functions I have saved in a file named functions.sh into a different script (protocol.sh). Can anybody show me how to do this? I tried source functions.sh as I would do at the terminal but source command cannot be found from within the script protocol.sh. ... (2 Replies)
Discussion started by: tevang
2 Replies

8. Shell Programming and Scripting

querry ..including external shell script

is there any way to include one shell script into other like include in c apart from putting it in a function (3 Replies)
Discussion started by: mobydick
3 Replies

9. Shell Programming and Scripting

Possible to call external script?

Hi Is it possible to have a bash script call an external bash script? For instance, I have a series of monitor scripts that check for running services (such as httpd, postmaster). Each monitor script is individual to the service. If a service fails, I would like to have a larger script that goes... (3 Replies)
Discussion started by: mikie
3 Replies

10. UNIX for Dummies Questions & Answers

Return info from a called external script

New to Unix scripting and have written two scripts, one calling the other. When it returns to the calling script is it possible to return information, like a return code? :confused: (1 Reply)
Discussion started by: cathrop
1 Replies
Login or Register to Ask a Question