Sponsored Content
Top Forums Shell Programming and Scripting How to use 'expect' to pass UID & Password to a "for loop" in shell script? Post 302873813 by thisissouvik on Wednesday 13th of November 2013 08:00:24 AM
Old 11-13-2013
Thanks in2nix, ~XL for your valuable inputs Smilie

Tried tweaking in2nix's code to allign to my reqd with the following 'expect' code:

Code:
#!/usr/bin/expect -f
#
#

# set credentials
set u "msouvik"
set p "pass^123"

# get host name from command-line
set h [lindex $argv 0]

# set the command to run
set cmd "echo Hello Souvik!  >> /export/home/msouvik/echo.out.$h"

# spawn a connection to the host and run the given command
spawn -noecho ssh -t $u@$h $cmd

# handle the password prompt
expect "?assword:*"
send -- "$p\r"
send -- "\r"

# scp the data onto NIM server
spawn -noecho scp $u@$h:/export/home/msouvik/echo.out .

# done
expect eof

And then applied the below 'while' loop:

Code:
while read h
> do
> expect_script.sh $h
> done < lsnim

Below is the error I get while the script tries to create a /export/home/msouvik/echo.out.$h file on the target servers:

==[ Error ]==
msouvik@my_target_server1 password: msouvik@my_target_server1 password:
scp: /export/home/msouvik/echo.out.my_target_server1: No such file or directory

msouvik@my_target_server2 password: msouvik@my_target_server2 password:
scp: /export/home/msouvik/echo.out.my_target_server2: No such file or directory
==

Find it really weird 'coz the script is not able to create a file named /export/home/msouvik/echo.out.$h on the target servers, however it is able to do so without the $h suffix to the filename.

Any leads pls?


-- Souvik
P.S: I'll try to understand XL's script before I implement it tomorrow Smilie
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

shell script & sqlplus "plzz help"

hi friends, i m tryin to load data from one set of table to other i have sql procedure al ready for it..! i m going to load the procedure only if data in one of my table for example table "landing " have 10 records each attribute of this table is file_name status date ... (2 Replies)
Discussion started by: kulbir
2 Replies

2. Shell Programming and Scripting

How to include RETURN KEY with Background process "&" in Shell Script

Hello All, I am a newbie in Shell script programming, and maybe you can help me with my query. I need to write a shell script (mntServer.ksh) that will start a background process and also to be able to run another script. The mntServer.ksh script contains: #!/bin/ksh... (1 Reply)
Discussion started by: racbern
1 Replies

3. Shell Programming and Scripting

ssh through "expect" in shell script

Hi, I am trying to use "Expect" in shell script to ssh and do some work in remote server but I am unable to connect. Here is the code I am using. #save as test.sh set ip "10.10.10.10" set username "uname" set password "upass" spawn ssh $username@$ip expect "Password:" send... (8 Replies)
Discussion started by: shekhar2010us
8 Replies

4. Red Hat

files having Script which works behind "who" & "w" commands

Dear All, plz print the path of files which have the script of "who" & "w" commands. thnx in advance. (6 Replies)
Discussion started by: saqlain.bashir
6 Replies

5. Shell Programming and Scripting

Passing username and password to a script running inside "expect" script

Hi I'm trying to run a script " abc.sh" which triggers "use.sh" . abc.sh is nothing but a "expect" script which provides username and password automatically to the use.sh script. Please find below the scripts: #abc.sh #!/usr/bin/expect -f exec /root/use.sh expect "*name*" send... (1 Reply)
Discussion started by: baddykam
1 Replies

6. Shell Programming and Scripting

Shell script using expect to login to couple of remote servers and read "crontab -l"

I need a shell script using expect to login to couple of remote servers and read "crontab -l -u <username>" & "cat /etc/rc.local" & "df -h" and able to create output into a file saved locally with hostname.crontab & hostname.rc.local & disk.status. I can supply a file as list of hostname or IP... (4 Replies)
Discussion started by: jaipsharma
4 Replies

7. AIX

How to use 'expect' to pass UID & Password to a "for loop" in shell script?

Friends, Need someone's help in helping me with the below requirement for a script: > For a list of servers(over 100+), I need to login into each of them(cannot configure password-less ssh) & grab few configuration details < I know, this is possible through expect programming in a simple... (2 Replies)
Discussion started by: thisissouvik
2 Replies

8. Shell Programming and Scripting

How to pass password to "su account" in script?

Hi, I need to run a test script to check all test accounts, is it possible to pass the password to su in following command? I've got following error: $ echo "${password}" | su ${test_account} -c "check_account.sh" standard in must be a tty Thank you. - j (3 Replies)
Discussion started by: hce
3 Replies

9. Shell Programming and Scripting

Can someone please show me a very simple "expect" script to change password in Solaris please?

Ladies & Gents, Can one of you gurus please show me a very simple "expect" script to change the password in Solaris in a script, please? Nothing fancy, no error checking, no nothing. Just to change the password of a new user, it's all. Many thanks in advance. U guys have honestly earned my... (1 Reply)
Discussion started by: Hiroshi
1 Replies

10. Shell Programming and Scripting

Expect: spawn id exp5 not open while executing "expect "$" { send "sudo su -\r" }"

Hi All, i am trying to ssh to a remote machine and execute certain command to remote machine through script. i am able to ssh but after its getting hung at the promt and after pressing ctrl +d i am gettin the out put as expect: spawn id exp5 not open while executing "expect "$" {... (3 Replies)
Discussion started by: Siddharth shivh
3 Replies
asadmin-create-domain(1AS)					   User Commands					asadmin-create-domain(1AS)

NAME
asadmin-create-domain, create-domain - creates a domain with the given name SYNOPSIS
create-domain [--domaindir install_dir/domains] [--passwordfile filename] [--terse=false] [--echo=false] [--interactive=false] --adminport port_number --adminuser admin_user [--adminpassword password] [--instanceport 8080] [--domainproperties (name=value)[:name=value]*] domain_name create-domain creates a domain with the specified administration port number, administration user, administration password, and domain name. By creating a domain, an administration server is created in a directory named as the domain name. This command is supported in local mode only. If a user creates a domain in a non-default directory, the domain will not be automatically shutdown during uninstallation. OPTIONS
--domaindir directory where the domain is to be created. If specified, path must be accessible in the filesystem. If not speci- fied, the domain is created in the default install_dir/domains directory. --passwordfile file containing the domain application server password in the following form: AS_ADMIN_PASSWORD=password. Where password is the actual administrator password for the domain. --terse indicates that any output data must be very concise, typically avoiding human-friendly sentences and favoring well- formatted data for consumption by a script. Default is false. --echo setting to true will echo the command line statement on to the standard output. Default is false. --interactive if set to true (default), only the required options are prompted. --adminport port number of the domain application server listening for the administration requests. --adminuser administrative username for the specified domain. --adminpassword password to administer the domain application server. --instanceport port number of the http listener. The port number cannot be currently in use. --domainproperties list of the property name/value pairs for the domain to be created separated by the ":" character. The property value assignment character is =. Valid property names are: jms.port, orb.listener.port, http.ssl.port, orb.ssl.port, orb.mutualauth.port. Valid values are: http.ssl.port=1043:orb.ssl.port=1060:orb.mutu- alauth.port=1061:jms.port=7676. OPERANDS
domain_name name of the domain. Must be a unique name. Example 1: Using create-domain asadmin> create-domain --domaindir /export/domains --adminport 7070 --adminuser admin --adminpassword adminadmin --instanceport 7071 sampleDomain created domain sampleDomain successfully Where: the sampleDomain domain is created in the /export/domains directory. EXIT STATUS
0 command executed successfully 1 error in executing the command asadmin-delete-domain(1AS), asadmin-start-domain(1AS), asadmin-stop-domain(1AS), , asadmin-list-domains(1AS) J2EE 1.4 SDK March 2004 asadmin-create-domain(1AS)
All times are GMT -4. The time now is 09:35 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy