Linux - ServerThis forum is for the discussion of Linux Software used in a server related context.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I have 20 Machines in site A
I have 1 Machine (i will call it machine1) in site B
In site A we have around 40 Users users in site A has to be connect to site B machine1 (using always user1) in shell script from all 20 Machines from site A. We can do password less authentication but my case 20 Machines and 40 different users
expect is the right way ? but I want to run shell script also How to done this?
You do this by writing a shell script and/or an expect script. Can you post what you've done/tried so far? See the "Question Guidelines" link in my posting signature...we are happy to help, but we aren't going to write scripts for you.
And your 'requirement' makes little sense. You say you have 40 users, who need to connect to another machine...all with the same user id, through a shell script. That's fine...so what's the problem? If they ALWAYS log in with "user1", then do your SSH keyswap, and tell the shell script to use it. Otherwise, just keyswap all 40 of your users from their workstations to machine1, and have your remote shell script do something like "sudo su - user1", allowing each user to log in as themselves, and assume the role of user1 at login. There is AMPLE documentation on how to write expect scripts you can easily find with a Google search. Read the "Question Guidelines" link in my posting signature.
Please explain what you're trying to accomplish, and show us what you've done so far. You may also want to message user Sagar666 on this site...I believe they have some experience with SSH. But I believe that's your other user name, isn't it? http://www.linuxquestions.org/questi...xi-4175552911/
Below is the script its just example to show where i struck
#get current directory
arg3=`pwd`
#directory path defined
path=/home/user1/a5/gen/rel/src
# Connect to remote machine and pass script arguments
sshpass -p 'abc' ssh -o StrictHostKeyChecking=no user1@cin $arg1 $arg2 $arg3
#get total fields of directory
T_field=`echo "$path" | awk -F"/" "{ print NF }"`
a=1
b=3
#get fourth and second field number only
Fourth="$((T_field - a))"
Second="$((T_field - b))"
#get field names
F_field=`echo "$path" | cut -d'/' -f$Fourth`
S_field=`echo "$path" | cut -d'/' -f$Second`
echo "$F_field"
echo "$S_field"
echo "arg1"
#get only directories name and send to output
ls -d */ > /home/lint/
#go to each directory and do some commands
while read line
do
cd line
hg pull; hp update
cd ..
done < output
In above script its just login to remote machine and not passing arguments and not running further script. Here I need help
Last edited by asteroid4u; 12-03-2015 at 12:41 AM.
Sorry I missed it actually user gives two arguments.
Below is the script its just example to show where i struck
[code]
#!/bin/sh
#get current directory
arg3=`pwd`
#directory path defined
path=/home/user1/a5/gen/rel/src
# Connect to remote machine and pass script arguments
sshpass -p 'abc' ssh -o StrictHostKeyChecking=no user1@cin $1 $2 $arg3
#get total fields of directory
T_field=`echo "$path" | awk -F"/" "{ print NF }"`
a=1
b=3
#get fourth and second field number only
Fourth="$((T_field - a))"
Second="$((T_field - b))"
#get field names
F_field=`echo "$path" | cut -d'/' -f$Fourth`
S_field=`echo "$path" | cut -d'/' -f$Second`
echo "$F_field"
echo "$S_field"
echo "arg1"
#get only directories name and send to output
ls -d */ > /home/lint/
#go to each directory and do some commands
while read line
do
cd line
hg pull; hp update
cd ..
done < output
[code]
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.