nixCraft Linux Forum

nixCraft

Linux / UNIX Tech Support Forum

Pause script execution untill each line is complete

This is a discussion on Pause script execution untill each line is complete within the Shell scripting forums, part of the Development/Scripting category; Hello, I need to run SERVERS="server1 server2...." for b in $SERVERS do echo $b; ssh $b grep 'abstract-photos.com' /etc/named.conf echo ...


Go Back   nixCraft Linux Forum > Development/Scripting > Shell scripting

Linux answers from nixCraft.


Shell scripting You can discuss the shell scripting, request shell scripts and scripting techniques

Reply

 

LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-11-2008, 11:01 AM
Junior Member
User
 
Join Date: Jul 2008
Location: SM
OS: CentOs
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
cosminnci is on a distinguished road
Default Pause script execution untill each line is complete

Hello,

I need to run

SERVERS="server1 server2...."
for b in $SERVERS
do
echo $b;
ssh $b grep 'abstract-photos.com' /etc/named.conf
echo "";
done

but before this need to add the ssh key:

exec ssh-agent bash
ssh-add /root/.ssh/my-key/

how can I include in the same script both so that when I run the script it prompts for the paraphrase and run the script?




and kind of the same with an script that creates a user on the system

/usr/sbin/useradd myuser
passwd myuser
mkdir ~/downloads
cd ~/downloads
wget...

how to write this so it does not cut off when requesting for the password?


Regards,

Cosmin
Reply With Quote
  #2 (permalink)  
Old 12-11-2008, 03:29 PM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
OS: RHEL
Scripting language: Bash and Python
Posts: 2,710
Thanks: 11
Thanked 245 Times in 184 Posts
Rep Power: 10
nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute
Default

You can either use sshpass to set password in script or use ssh keys for passwordless login:
  1. sshpass: Login To SSH Server / Provide SSH Password Using A Shell Script
  2. Howto Linux / UNIX setup SSH with DSA public key authentication (password less login)
__________________
Vivek Gite
Linux Evangelist
Be proud RHEL user, and let the world know about your enterprise choices! Join RedHat user group.
Always use CODE tags for posting system output and commands!
Do you run a Linux? Let's face it, you need help
Reply With Quote
  #3 (permalink)  
Old 12-11-2008, 05:01 PM
Junior Member
User
 
Join Date: Jul 2008
Location: SM
OS: CentOs
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
cosminnci is on a distinguished road
Default

Thanks for the solution but rather than storing the pass better typeing it once before starting the script.


about this other thing:

/usr/sbin/useradd myuser
passwd myuser
mkdir ~/downloads
cd ~/downloads
wget...

how to write this so it does not cut off when requesting for the password?
Reply With Quote
  #4 (permalink)  
Old 12-11-2008, 06:20 PM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
OS: RHEL
Scripting language: Bash and Python
Posts: 2,710
Thanks: 11
Thanked 245 Times in 184 Posts
Rep Power: 10
nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute
Default

Quote:
Originally Posted by cosminnci View Post
how to write this so it does not cut off when requesting for the password?
Are you talking about wget password?
__________________
Vivek Gite
Linux Evangelist
Be proud RHEL user, and let the world know about your enterprise choices! Join RedHat user group.
Always use CODE tags for posting system output and commands!
Do you run a Linux? Let's face it, you need help
Reply With Quote
  #5 (permalink)  
Old 12-11-2008, 06:49 PM
Junior Member
User
 
Join Date: Jul 2008
Location: SM
OS: CentOs
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
cosminnci is on a distinguished road
Default

I want to create a script to install nagios addon on several machines.

but when pasting

/usr/sbin/useradd myuser
passwd myuser
mkdir ~/downloads
cd ~/downloads
wget http://surfnet.dl.sourceforge.net/sourceforge/
wget http://surfnet.dl.sourceforge.net/sourceforge/
tar xzf nagios
tar xzf nagios
......................

it shows all this and prompts for the pass , after entering the pass it does not complete the rest..

mkdir ~/downloads
cd ~/downloads
wget http://surfnet.dl.sourceforge.net/sourceforge/
wget http://surfnet.dl.sourceforge.net/sourceforge/
tar xzf nagios
tar xzf nagios
......................

can it be somehow that I paste the block of code and it is beeing procesed line by line? and wait for user input where it is needed.
Reply With Quote
Reply

Tags
password , shell script , shell scripting , ssh


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads

Thread Thread Starter Forum Replies Last Post
HPUX Unix comparing 2 large files line by line raj HP-UX 1 11-02-2008 05:20 PM
Complete NOOB need help gham Shell scripting 0 04-06-2007 09:56 PM
Omit the first line in a file c341 Shell scripting 4 29-12-2006 02:07 PM
speeding up execution kavi Linux software 6 16-10-2005 04:31 PM


All times are GMT +5.5. The time now is 12:55 AM.


Powered by vBulletin® Version 3.8.5 - Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2
©2005-2010 nixCraft. All rights reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38