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 :slight_smile:

BS

You seem to have a space between $ and Password on this line: Password $ PASSWD. That may be causing it.

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:

while true
do

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:

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

.
Also read is answer = run once and parse.
Generic version:

read h m s <<EOF
$(date '+%H %M %S')
EOF

Ksh can do also:

date '+%H %M %S' | read h m s

Array is also nice method, if you have list of values

values=(   $(date '+%H %M %S')  )
# ${values[0]} is 1st value
# ${#values[*]} number of values

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

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

```text
 and 
```

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

Put your script using CODE-blog using cut-paste, because your message not include working ksh script. Something like:

#!/bin/ksh
#Login as Appadmin

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