shell scripting


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting shell scripting
# 1  
Old 09-14-2010
shell scripting

Hi ,
I have installed expect on the server and I am trying to execute the script but getting below error.Please suggest me the way out.
I would like to know how cct can be utilized here to call extlog.exp?

Code:
./passwdchng.sh
Enter your password:
password
dbaguest,192.168.175.1,password
./passwdchng.sh: logext.exp: command not found
oracle,192.168.175.2,password
./passwdchng.sh: logext.exp: command not found
root,192.168.175.3,password
./passwdchng.sh: logext.exp: command not found

Sripts are:--
#!/bin/bash

Code:
username="dbaguest"
echo "Enter your password:"
read newPassword
cat ssh.csv | while read line;
do
host=`echo $line | cut -d, -f1`
addr=`echo $line | cut -d, -f2`
paswd=`echo $line | cut -d, -f3`
echo "$host,$addr,$paswd"
cct=$(logext.exp $paswd $newPassword $addr $username)if [[ "$cct" == *login* ]]; then
echo "SSH Connection to $host succeeded" >> testlog
if [[ "$cct" == *successfully* ]]; then
echo "Password has been changed successfully for $host" >> testlog
else
echo "Password change failed for $host." >> testlog
echo "$host,$addr,$paswd" >> errorlog
fi
else [[ "$cct" == *Permission* ]]
echo "$host,$addr,$paswd" >> errorlog
fi
cct=""
done

Code:
#!/usr/bin/expect -f
set currentpasword [lrange $argv 0 0]
set newpassword [lrange $argv 1 1]
set ipaddr [lrange $argv 2 2]
set username [lrange $argv 3 3]
set cmd "passwd"
spawn /usr/bin/ssh -X $username@$ipaddr
expect -re "Enter password for key'.*':"
send "yes\r"
expect "*password*"
send "$currentpasword\r"
expect "%"
expect "Last login:" {
send "$cmd\r"
expect "%"
expect "*(current) UNIX password*"
send "$currentpasword\r"
expect "*New UNIX Password*"
send "$newpassword\r"
expect "*Retype*"
send "$newpassword\r"
expect "%"
expect "exit\r"
}

Regards,
Mk

Last edited by pludi; 09-14-2010 at 08:19 AM.. Reason: code tags, please...
# 2  
Old 09-14-2010
Code:
cct=$(logext.exp $paswd $newPassword $addr $username)if [[ "$cct" == *login* ]]; then

Are you sure there should be not a new line before if ?

Change to:

Code:
cct=$(logext.exp $paswd $newPassword $addr $username)
if [[ "$cct" == *login* ]]; then

# 3  
Old 09-14-2010
Try exporting the PATH variable within passwdchng.sh script to have the correct path where the logext.exp resides
# 4  
Old 09-14-2010
Hi,
Thanks for you reply.this file is present in the same directy.Is there any other method so that I can call this file and excute.
# 5  
Old 09-17-2010
Hi,
Thanks for you reply!! Now this problem got resoved.
Now I am not able to connect remote host using ssh ,however with the same password I am able to connect menually.here I am listing the output.Please give your suggestion.

+ echo dbaguest,192.168.12.1,password
dbaguest,192.168.12.1,password
./test.exp $paswd $newPassword $addr $username
++ ./test.exp password newpassword 192.168.12.1 dbaguest
+ cct=spawn ssh -t dbaguest@192.168.12.1
dbaguest@192.168.12.1's password:
password
Permission denied, please try again.
dbaguest@192.168.12.1's password:
+ [[ spawn ssh -t dbaguest@192.168.12.1
dbaguest@147.149.205.13's password:
password
Permission denied, please try again.
dbaguest@192.168.12.1's password: == *login* ]]
+ [[ spawn ssh -t dbaguest@192.168.12.1
dbaguest@192.168.12.1's password:
password
Permission denied, please try again.
dbaguest@192.168.12.1's password: == *Permission* ]]
+ echo ,192.168.12.1,password
,192.168.12.1,password
+ cct=
+ read line
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Shell script to read lines in a text file and filter user data Shell Programming and Scripting

sxsaaas (3 Replies)
Discussion started by: VikrantD
3 Replies

2. Shell Programming and Scripting

help me in Shell Scripting

Hi there please have a look at the code..i want to create Using a named pipe. Run a find in the background starting in the working directory While this is happening wait for input from the user to ask him which file to find. If the user does not enter any data in 10 seconds ask the user again.... (1 Reply)
Discussion started by: kattak1511
1 Replies

3. Shell Programming and Scripting

Shell scripting

Hi, if in a network there are lots of PCs connected with either windows or linux as operating system.Then what will be the shell script for the same and also if the PC has linux in it then we have to find if it is occupied or unoccupied. If the PC has windows in it then we have to find if it is... (6 Replies)
Discussion started by: akansha singh
6 Replies

4. UNIX for Dummies Questions & Answers

Shell Scripting

Hey I have a data in the file named as outputFile.txt. The data is in the format 123456,12345678912345,400,09/09/09,INACTIVE. I want this output without commas ie 12345612345678912345400090909INACTIVE. Please tell me what to do and clear explain all the terms, as I am new to it. (6 Replies)
Discussion started by: sampandey31
6 Replies

5. Web Development

Perl scripting or shell scripting?

i am going to study any one of the scripting languages mentioned above(shell 0r perl scripting) . Which is having more scope for a fresher? (1 Reply)
Discussion started by: Anna Hussie
1 Replies

6. What is on Your Mind?

Shell Scripting vs Perl scripting

Gents, I have been working in a Solaris/Unix environment for about 9 months. I took some linux classses online before getting the job. But, I am not very good at scripting. I want to learn how to script. Do you think that I should start with Shell scripting or Perl? I wanted to continue with... (2 Replies)
Discussion started by: Pouchie1
2 Replies

7. Android

Android Scripting Environment: Shell Scripting and Android

I just upgraded to Android 2.2 from 2.1. The GPS issue that was troublesome in 2.1 seems to have been fixed. Some of web browsing seems faster, but it could just be my connection is better today ;) Flash works in some browsers but not very good and it is too slow for Flash apps designed for... (0 Replies)
Discussion started by: Neo
0 Replies

8. What is on Your Mind?

Shell scripting vs Perl scripting

Hi all, I would like to start developping some good scripting skills. Do you think it would be best to start with shell scripting or Perl? I already got a fundation, really basics, in perl. but I am wondering what would be best to be good at first. Can you please help me determine which one to... (14 Replies)
Discussion started by: Pouchie1
14 Replies

9. Shell Programming and Scripting

Call Shell scripting from Perl Scripting.

Hi How to call a shell scripting through a Perl scripting? Actually I need some value from Shell scripting and passes in the Perl scripting. So how can i do this? (2 Replies)
Discussion started by: anupdas
2 Replies

10. Shell Programming and Scripting

difference between AIX shell scripting and Unix shell scripting.

please give the difference between AIX shell scripting and Unix shell scripting. (2 Replies)
Discussion started by: haroonec
2 Replies
Login or Register to Ask a Question