How to write automated interactive shell script?

 
Thread Tools Search this Thread
Special Forums UNIX and Linux Applications How to write automated interactive shell script?
# 1  
Old 07-09-2013
Wrench How to write automated interactive shell script?

Hello everyone, I just want to write a shell script for automatic feeding the username and password prompts when running my commands,
I tried this one but it did not work. Please help me for any way out.

Code:
#!/bin/bash
#!/usr/bin/expect

cd ~/workspace/mimosanetworks_mimosa-nms

ls -ltr

spawn sudo git pull

expect "[sudo] password for sandeep:"

send "sandeep123\n"

expect "Username :"

send "sandeep\n"

expect "Password :"

send "sandeep121\n"

# 2  
Old 07-09-2013
Whats the problem are you facing? I guess if you just do some digging around the forum u will get many except script examples.
# 3  
Old 07-09-2013
I get the following output

Code:
sandeep@K2-Sandeep-08:~$ ./checkout.sh 
total 64
./checkout.sh: line 8: spawn: command not found
couldn't read file "Username:": no such file or directory
./checkout.sh: line 16: send: command not found
couldn't read file "Password:": no such file or directory
./checkout.sh: line 20: send: command not found

# 4  
Old 07-09-2013
do you have expect utility installed on your server?
# 5  
Old 07-09-2013
Yes. Expect utility is installed. I donno whether send and spawn utitlity exists? as I tried through "apt-get", der is no such utility
# 6  
Old 07-09-2013
i would strongly advise against scripting a password-required process for the usual security reasons ...

anyways, see if a here document could work for you ... (see sample below) ...
Code:
otto@susegeek:~> su - << EOF
> B0r3d2!
> id
> ps
> EOF
Password: uid=0(root) gid=0(root) groups=0(root)
  PID TTY          TIME CMD
 6423 pts/1    00:00:00 su
 6426 pts/1    00:00:00 bash
 6455 pts/1    00:00:00 ps
otto@susegeek:~>

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Interactive Python 3.5+ sys.stdout.write() AND sys.stderr.write() bug?

(Apologies for any typos.) OSX 10.12.3 AND Windows 10. This is for the serious Python experts on at least 3.5.x and above... In script format sys.stdout.write() AND sys.stderr.write() seems to work correctly. Have I found a serious bug in the interactive sys.stdout.write() AND... (2 Replies)
Discussion started by: wisecracker
2 Replies

2. Shell Programming and Scripting

Help with Automated Shell Script

Hello, how can I write a shell script that looks in running processes and if there isn't a process name containing 91.34.124.35 then execute a file in a certain place. I know PHP, in PHP I could do a preg_match_all but I don't know how to do it in shell. (5 Replies)
Discussion started by: nottingham
5 Replies

3. Shell Programming and Scripting

Write an automated shell program(s) that can create, monitor the log files and report the issues for

Hi , Please help me getting this done. Write an automated shell program(s) that can create, monitor the log files and report the issues for matching pattern. (i) Conditions for creating log files. Log file is created with date (example 2010_03_27.log). If the log file size is 10 Mb for... (1 Reply)
Discussion started by: itian2010
1 Replies

4. Shell Programming and Scripting

How to automated the shell script

hye there... really need ur help... i have a file ./filename... then i want to make ./filename automatic run... for example: if someone send me a file using scp...then the ./filename will run automatically... did u guys get what i mean.... if not please ask me... cz i really need ur help... (29 Replies)
Discussion started by: annetote
29 Replies

5. 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

6. 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

7. Shell Programming and Scripting

How to make interactive shell script a automated one?

Hi, I am new to shell scripting.I have written a very simple shell scipt that asks for the username and password on executing. i.e echo "Enter username :" read usrname; echol "Enter password :"; read passwd; echo usrname; echo passwd; but now I want to make it automatic , such... (2 Replies)
Discussion started by: bhaskar_m
2 Replies

8. Shell Programming and Scripting

how to write a shell script to login to a system which is interactive.

Can anybody help me to write a shell script to login interactive system once u open a connection using telnet it will ask for USERCODE: PASSWORD: DOMAIN: (1 Reply)
Discussion started by: sudhakaryadav
1 Replies

9. Shell Programming and Scripting

Need automated shell script please

I'm totally new to shell scripting and I would like to ask your help 1.i want to have a .sh script where it runs opening 2 applications one after another 2.i have 2 applications in /applications/app1 /applications/app2 3. want this script to launch app1 for 20 seconds and get killed... (2 Replies)
Discussion started by: uneex
2 Replies

10. Shell Programming and Scripting

Need help for automated shell script

hi, I have a system with 3 O/S on it ( win 32, RHEL 4 32 & 64) I'm very new to shell scripting and I'm seeking for help in this matter.. I want to have an automated script on REDHAT that would run/open multiple applications one after other timed out at 20 seconds interval. Eg:... (4 Replies)
Discussion started by: uneex
4 Replies
Login or Register to Ask a Question