Visit The New, Modern Unix Linux Community


Script as login shell (passing args to login shell)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script as login shell (passing args to login shell)
# 1  
Script as login shell (passing args to login shell)

Hello all,

for security reasons my compagny imposes that my script be launch remotly via ssh under the users login shell.

So serverA launches the ssh command to serverB which has a local user with my script as a login shell.

Local script works like a charm on his own.

Code:
serverB$ grep user1 /etc/passwd
user1:x:921:921::/home/user1:/home/user1/insert_host_ip_named.bash

serverA$ ssh -t user1@serverB

Everything works fine until i bring up arguments

For testing purpose i've replaced the 3 first lines of my script with:
Code:
echo $#
echo $*
sleep 3
exit

and i get this:
Code:
 ssh user1@serverB -- "-i 275.30.44.55 -n WYWYOU"
2
-c -i 275.30.44.55 -n WYWYOU

Which is not good cause the script needs at least 4 args to run:
Code:
# Check number of arguments
case $# in
         4|5) ;;
         *) usage; exit 1 ;;
esac

Any way too make him pass more than 2 arguments?... and he's probably counting the -c as one.
# 2  
It would help if you show the script. How are you executing this? What is the command you send over to the server. Since you didn't supply the script I created x.sh that just outputs argument count, arguments...
Code:
echo $# 
echo $* 
exit

I didn't have problems with argument counting. This works....
Code:
[josephgr@oc0887178221 ~]$ ssh josephgr@freezer1 ./x.sh  "-i 275.30.44.55 -n WYWYOU"
josephgr@freezer1's password: 
4
-i 275.30.44.55 -n WYWYOU

This User Gave Thanks to blackrageous For This Post:
# 3  
Thanks for the anwser but the real problem is the script is actually the remote user login shell which is in the home of the remote user.

- serverA ssh serverB with user1
- user1 login shell is x.sh
- user1's home on serverB contains x.sh which gets exec upond login.
- can't pass args too that exec via ssh

Keys are handle and scripts exec is handle too. Only params poses a problem. Hope it is clearer (been banging my head on that since Friday).
# 4  
What are the contents of x.sh? If it's mangling arguments, it will have to be worked around, and one can hardly tell that without knowing what it is.
This User Gave Thanks to Corona688 For This Post:
# 5  
Quote:
Originally Posted by maverick72
Any way too make him pass more than 2 arguments?... and he's probably counting the -c as one.
Yes, "-c" is one argument and the rest is the second. Your problem is not the passing of the parameters but the splitting of them.

You could emulate the splitting along IFS characters inside your shell this way:

Code:
#! /bin/ksh
args="$1"
IFS=" "
while : ; do
     print - "next: ${args%%${IFS}*}"
     if [ "$args" != "${args#*${IFS}}" ] ; then
          args="${args#*${IFS}}"
          print - "rest: $args"
     else
          print - "rest:"
          break
     fi
done

When run it looks like this:

Code:
# ./split.ksh 'a     b c def g h'
next: a
rest:     b c def g h
next: 
rest:    b c def g h
next: 
rest:   b c def g h
next: 
rest:  b c def g h
next: 
rest: b c def g h
next: b
rest: c def g h
next: c
rest: def g h
next: def
rest: g h
next: g
rest: h
next: h
rest:

Notice that you will have to throw out empty "args" in the loop to compensate for multiple consecutive IFS chars.

I hope this helps.

bakunin
This User Gave Thanks to bakunin For This Post:
# 6  
Ohhhh i get it now... Yeah well like you guys said the problem will be the parsing.

For the script it is a script that edit's a dns file and relaunches the process.

Code:
$ insert_host_ip.bash -i <ip> -n <name record> [-d] (to delete the record)

So basicly the args are "-i" "-n" "ip address" "name_record" "-D"

Nothing with spaces or weird chars but i do parse my options with a basic getops

Code:
# Parse the arguments
while getopts i:n:R OPTION; do
  case "$OPTION" in
        D) REMOVE=Y
        ;;
        i) IP_ADDRESS=$OPTARG
        ;;
        n) NAME_RECORD=$OPTARG
        ;;
        :) usage ; exit 5
        ;;
        \?) usage ; exit 5
        ;;
  esac
done

shift $((OPTIND-1))

# 7  
No, I mean -- what are the contents of x.sh? The shell script that gets executed on login?
This User Gave Thanks to Corona688 For This Post:

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #16
Difficulty: Easy
There are a total of 25 pins in the traditional parallel port of a computer system.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script for login user and email

Guys please help me I have a linux class and I want to write a shell script who shows which user loged in and show the process that are active in his/her shell in another text file and email that file to root just when the user loged out Thanks every bod (1 Reply)
Discussion started by: hamedk1122
1 Replies

2. Shell Programming and Scripting

How to login as a different user inside a shell script?

hi, i want to login as a different user inside a shell script and then call another shell script from that script. how to do that? original script : script_A.sh so when the script_A.sh is called , i want to login as a different user and then call another shell script(script_B.sh) from... (3 Replies)
Discussion started by: Little
3 Replies

3. Shell Programming and Scripting

passing login details to htaccess login prompt

Hi, How i can pass the login details to the URL which is password protected with the htaccess using command line or script (perl,or shell,or php). Any help or hint appreciated. Thanks, SJ (4 Replies)
Discussion started by: SilvesterJ
4 Replies

4. Shell Programming and Scripting

Help with Unix bash shell script login

Hi, I am a complete Unix novice and need some help with creating a login shell script. I have created a file with user details i.e. PIN, name etc and require help in recalling the specified details from the file and being prompted for a password on login. Any help would be very much appreciated.... (0 Replies)
Discussion started by: tdsrogers
0 Replies

5. Shell Programming and Scripting

SSH - Passing Unix login passwords through shell scripts

Hi All , I need to call a script runscript_B.sh on server A, the runscript_B.sh script locating in server B. The runscript_B.sh in calls another script runscript_A on server A itself. it seend, i need to be connect from Server A to Server B using ssh. I have tryed like this in... (3 Replies)
Discussion started by: koti_rama
3 Replies

6. Shell Programming and Scripting

Login with Shell Script.

Dear All, I need to create a shell script which will login to a unix system with user root. I also need to supply the password for root through script only instead of entering it manually. After i am logged in to the system i need to excute all the necessary commands. so far i have done... (7 Replies)
Discussion started by: Siddheshk
7 Replies

7. Shell Programming and Scripting

login from a shell script?????

Any help on this ..... its a bit urgent !!!! Hi Can anybody provide info about the following??? i want to issue su (switch user) command from within a shell script how to take the password without user intervention from the shell script only???? i.e using apssword which is already... (2 Replies)
Discussion started by: skyineyes
2 Replies

8. HP-UX

cannot login after changing login shell

Hello Everyone, I am a newbie in unix. I was practicing shell scripts on hp unix machine. I changed my current login shell (Korn) to Bourne shell giving the following command. $ chsh username /usr/bash I am using secure shell client for accessing the hp ux server. After which i... (4 Replies)
Discussion started by: hardesh
4 Replies

9. Shell Programming and Scripting

remote-login via Shell-Script

Hello all, I would like to login from one unix-system with a (tcsh)-script to an other unix-system.The login-procedure and the transmission of username, resp. password runs via ssh. The problem is after logging onto the remote server once "Enter" has to be pressed, before one gets to the... (1 Reply)
Discussion started by: Juergen Paepke
1 Replies

10. UNIX for Dummies Questions & Answers

remote login via shell script

is it possible for me to have a shell script log me in to a telnet session? i have in mind something along the lines of % telnet host < script, where the first two lines of script will be username and pass followed by a list of commands to execute on the remote host. this doesn t work as... (4 Replies)
Discussion started by: lethe
4 Replies

Featured Tech Videos