Visit Our UNIX and Linux User Community


Changing shell from a script and running something from the new shell


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Changing shell from a script and running something from the new shell
# 1  
Old 10-29-2014
Changing shell from a script and running something from the new shell

Hi

We use "tcsh" shell . We do the following steps manually:
> exec ssh-agent zsh
> python "heloo.py" (in the zsh shell)

I am trying to do the steps above from a shell script

This is what I have so far


Code:
echo "Executing "
exec ssh-agent zsh
python "hello.py"
exit 0


Problem is step 2 above . The script just sits on the zsh prompts and waits for user to type "exit" and then runs the python script from tcsh shell (original shell)

What can i do in the script for it to run
python "hello.py" from the zsh shell instead?

Thanks in advance
# 2  
Old 10-30-2014
I am not a csh or csh-derivative expert by any stretch of the imagination, but I don't understand why it matters at all which shell invokes python or why anyone would want to invoke a shell to invoke another shell to invoke python???

Why isn't your script just:
Code:
ssh-agent python "hello.py"
exit 0

# 3  
Old 10-30-2014
I am integrating SW components from two different teams. We want to use tcsh shell all the time but want to run this python framework in z shell (i don't know the reason for that)

Right now we do it manually . I am looking to put that in a shell script . But i am not able to achieve that yet

Thanks
# 4  
Old 10-30-2014
That trick only works if the script is read from standard input.

Code:
sh -s <<EOF
echo "stuff"
# Some other command which reads the following lines
ssh user@host
echo \$HOSTNAME
EOF

This is because the command could not otherwise know what file to read from.
# 5  
Old 10-30-2014
i apologize i don't follow what do you mean

Thanks !
# 6  
Old 10-31-2014
I mean exactly what I said. If you do bash filename or ./filename it cannot "switch" to a new shell, language, whatever in the middle -- the new program will lose track of "filename".

You have to do bash -s < scriptname to allow it to change horses in midstream. The new program doesn't have to re-open filename -- it never opened it in the first place, they all just read from standard input.

Last edited by Corona688; 10-31-2014 at 01:16 PM..

Previous Thread | Next Thread
Test Your Knowledge in Computers #701
Difficulty: Easy
MySQL NOT LIKE is a sardonic DB operator used to exclude those rows which are not liked by Oracle Corporation executives.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Cp not working in shell script but running perfectly from shell

Dear All, I have script. Dest="" IFS=' ' for translation in $(echo $MY_MAP) do t1=$(echo $translation | cut -d"=" -f1) t2=$(echo $translation | cut -d"=" -f2| cut -d"," -f1) if then Dest=$UNX/$u_product_path/$u_study_path/$UNXTR/$t2 break; ... (4 Replies)
Discussion started by: yadavricky
4 Replies

2. Shell Programming and Scripting

Running 3 shell script parallel in another shell script

Hi, I'm trying to do teh below thing. I have a single script which uses 3 different parameters to do 3 different work like belwo. test1.sh par1 -- it shuts down an instance test1.sh par2 -- it shuts down an instance test1.sh par3 -- it shuts down an instance Now I created a script... (7 Replies)
Discussion started by: bhaski2012
7 Replies

3. Shell Programming and Scripting

Help with shell script on Month Changing Logic

Hi Unix Experts, Happy Morning to all !! :) I am new to UNIX Shell Scripting and at my begineer level. To get acquainted to scripting, I am trying to create a script. The details/requirements of my script was to create a script with month changing logic in it so that on every 6th Working... (3 Replies)
Discussion started by: micky3112
3 Replies

4. Shell Programming and Scripting

Shell script running command in different shell

Hi All, Is there any way where we can run few commands with different shell in a shell script ? Let's have an example below, My first line in script reads below, #!/bin/sh However due to some limitation of "/bin/sh" shell I wanted to use "/bin/bash" while executing few... (9 Replies)
Discussion started by: gr8_usk
9 Replies

5. UNIX for Dummies Questions & Answers

Changing permissions in a shell script

Hi All, I have a shell script which we keep on changing permissions on a On-Demand Basis-->for e:g--from 400(Read only) to 740(Execute permission) etc. Is there any way by which I can view the history of the script?-->I am interested in finding out the date-time stamps when the script's... (2 Replies)
Discussion started by: DevotedPupil
2 Replies

6. Shell Programming and Scripting

Regarding changing shell thru script

Guys can I change the shell thru script, and after changing i want the script to continue on the previous machine. Or please suggest other alternative if any??? #!/bin/ksh HOST=`hostname` echo "Running the script..." for MyServer in `cat ServerNames.txt` do echo "\n Logging onto... (4 Replies)
Discussion started by: sdosanjh
4 Replies

7. Shell Programming and Scripting

Changing value of a variable inside a shell script

I have a continous polling happening inside a shell script on AIX. This actually calls a PL/SQL block. Is there a way I can set up a variable or pass an interrupt to end the script gracefully. I cant read from the config once the job starts running. Ideally I should change value of a variable and... (1 Reply)
Discussion started by: kshyju
1 Replies

8. Shell Programming and Scripting

How to run cmds after changing to a new env (shell) in a shell script

Hi, I am using HP-UNIX. I have a requirement as below I have to change env twice like: cadenv <env> cadenv <env> ccm start -d /dbpath ccm tar -xvf *.tar ccm rcv .... mv *.tar BACKUP but after I do the first cadenv <env> , I am unable to execute any of the later commands . ... (6 Replies)
Discussion started by: charlei
6 Replies

9. Shell Programming and Scripting

Changing cursor position using shell script

Hi, Pleae help me on this. Normally, when we say read username, the cursor will come in the first position of next line, but I want the output of the below Normal usage ------------- please enter username: _ I want like the below ---------------------- please enter username: ... (2 Replies)
Discussion started by: balamv
2 Replies

10. Shell Programming and Scripting

Password changing in a Script (shell and expect)

Hi, Does anybody know how to change the password on multiple servers with a script. I have 300 Sun boxes and the password expiry is set to 30 days. Im in a process to build a script using expect. Need a help from an expert who has already done it. Regards, Vinod (1 Reply)
Discussion started by: chellam
1 Replies

Featured Tech Videos