LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 07-31-2007, 12:33 PM   #1
lhouk
LQ Newbie
 
Registered: Apr 2004
Location: Houston, Texas USA
Distribution: Fedora 8 (mostly)
Posts: 15

Rep: Reputation: 0
Can't change shell in plink shell script?


I'm using plink to execute the shell script "plink_script" using the command
Code:
plink.exe -ssh -m plink_script -l user remote_sys
This works, but the default shell for user's account is /bin/tcsh, and plink_script needs to run under /bin/bash. For the life of me, I can't get plink_script not to run under /bin/tcsh!

If plink_script is just the single line
Code:
echo "$SHELL"
running the plink command produces the expected output
Code:
/bin/tcsh
However, when I tried changing plink_script to be
Code:
#!/bin/bash
echo "$SHELL"
to my surprise the output was still
Code:
/bin/tcsh
I thought this would be simple, but it's got me stumped. Anyone know what I should do to get plink_script to output
Code:
/bin/bash
Thanks in advance to all who respond!
 
Old 07-31-2007, 08:44 PM   #2
cfaj
Member
 
Registered: Dec 2003
Location: Toronto, Canada
Distribution: Mint, Mandriva
Posts: 221

Rep: Reputation: 31
Quote:
Originally Posted by lhouk
I'm using plink to execute the shell script "plink_script" using the command
Code:
plink.exe -ssh -m plink_script -l user remote_sys
This works, but the default shell for user's account is /bin/tcsh, and plink_script needs to run under /bin/bash. For the life of me, I can't get plink_script not to run under /bin/tcsh!

If plink_script is just the single line
Code:
echo "$SHELL"
running the plink command produces the expected output
Code:
/bin/tcsh
However, when I tried changing plink_script to be
Code:
#!/bin/bash
echo "$SHELL"
to my surprise the output was still
Code:
/bin/tcsh
I thought this would be simple, but it's got me stumped. Anyone know what I should do to get plink_script to output
Code:
/bin/bash
Thanks in advance to all who respond!

The SHELL variable contains the user's default shell, not the shell running the script.


 
Old 08-02-2007, 03:47 PM   #3
lhouk
LQ Newbie
 
Registered: Apr 2004
Location: Houston, Texas USA
Distribution: Fedora 8 (mostly)
Posts: 15

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by cfaj
The SHELL variable contains the user's default shell, not the shell running the script.
Please forgive my cluelessness. I tried to come up with a simple way of explaining my problem, but maybe I chose a bad example. A better "plink_script" shell script to demonstrate the issue might be the following:
Code:
if [ 1 -eq 1 ] ; then
    echo 'Always true'
fi
When run under bash, it just echoes "Always true", but when run under tcsh, it generates syntax errors. So, as expected, when I run it with:
Code:
plink.exe -ssh -m plink_script -l user remote_sys
given that the default shell for "user"s account is /bin/tcsh, it produces:
Code:
if: Expression Syntax.
Always true
fi: Command not found.
Now, I want plink_script to run under bash on remote_sys. When I tried
Code:
#!/bin/bash
if [ 1 -eq 1 ] ; then
    echo 'Always true'
fi
it still gave me
Code:
if: Expression Syntax.
Always true
fi: Command not found.
as did
Code:
alias shell /bin/bash
if [ 1 -eq 1 ] ; then
    echo 'Always true'
fi
and
Code:
set shell=/bin/bash
if [ 1 -eq 1 ] ; then
    echo 'Always true'
fi
and
Code:
#\!/bin/bash
if [ 1 -eq 1 ] ; then
    echo 'Always true'
fi
I can't figure out a way to make the entire plink_script run under bash.

Interestingly, if I run the original three-line version of plink_script after actually logging in as "user", it only displays the first "if: Expression Syntax" and exits. Perhaps plink.exe is sending each line of plink_script separately to remote_sys, and starting a separate process for each line?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to change directory in a shell script? jdupre Linux - Newbie 11 01-21-2012 09:01 AM
Shell script to change password kamal_aitin Linux - General 6 07-25-2007 01:09 AM
shell script + change shell && continue darkRoom Programming 6 02-25-2005 03:50 AM
How can i change the icon of a shell script? BajaNick Linux - Software 6 01-14-2004 01:56 AM
Shell script to change IP addresses saintt Linux - General 4 08-20-2001 12:17 PM


All times are GMT -5. The time now is 10:10 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration