LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices



Reply
 
Search this Thread
Old 04-21-2010, 07:53 AM   #1
casperdaghost
Member
 
Registered: Aug 2009
Posts: 348

Rep: Reputation: 16
running sh scripts from csh command line


i use the csh shell at work. you can either log on to servers locally or to the NFS mount. is is important to know which you are mounted to when executing scripts. csh is the only shell that lets me know which high availability server i am currently on.

before i write a shell script to complete a task, i have to type sh or bash at the prompt, hit enter and then configure the script. then when i am done, hit control -d to get out the bash or sh shell.

is there a way to run sh or bash scripts from the csh command line - i have tried typing this at the csh command line: /bin/sh (or ./bin/bash)
while [ 1 ]; do ps auxwww | grep fire | wc -l ; done ... etc, but it does not work.

we do not have the zsh shell at work
 
Old 04-21-2010, 08:13 AM   #2
linuxlover.chaitanya
Senior Member
 
Registered: Apr 2008
Location: Nagpur, India
Distribution: Cent OS 5/6, Ubuntu Server 10.04
Posts: 4,628

Rep: Reputation: Disabled
From the c shell cd to the directory where the shell script is and then run the script like

sh script.sh.
 
Old 04-21-2010, 08:25 AM   #3
tronayne
Senior Member
 
Registered: Oct 2003
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,122

Rep: Reputation: 819Reputation: 819Reputation: 819Reputation: 819Reputation: 819Reputation: 819Reputation: 819
Try this: as the first line of your shell program, enter
Code:
#!/bin/sh
or
#!/bin/ksh
or
#!/bin/bash
That'll execute in the appropriate shell.

Also, particularly with C-Shell, you can set environment variables in your shell program that may not be set in C-Shell; e.g., simply
Code:
#!/bin/sh

export ENV_VAR=blah
export OTHER_ENV_VAR=blahblah
Life get better that way.

Hope this helps some.
 
Old 04-21-2010, 10:25 AM   #4
casperdaghost
Member
 
Registered: Aug 2009
Posts: 348

Original Poster
Rep: Reputation: 16
so i am not at work right now, but you are explaining that i should be able to go

cd /bin/sh ; while [ 1 ] ; do ps auxwww | grep fire | wc -l ; done

right from the csh command line - that would be acceptable.
 
Old 04-21-2010, 11:11 AM   #5
tronayne
Senior Member
 
Registered: Oct 2003
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,122

Rep: Reputation: 819Reputation: 819Reputation: 819Reputation: 819Reputation: 819Reputation: 819Reputation: 819
I'm sorry, I don't quite get what you're asking -- first off, you would not "cd /bin/sh" (/bin/sh is an executable file, not a directory). Many installations do not have the current directory in the user's PATH environment, so, to execute a shell program ("script"), you can cd to the directory where it resides then enter "./shell_prog_name" to execute that program. If your shell program has the "#!/bin/sh" as the first line of the program, it will be executed by the appropriate shell.

You can normally execute any executable program (irrespective of what the source code may be) from the C-Shell command prompt; the example you've given is a Shell while loop (which will not, I'm sure you've discovered, execute in C-Shell). You can,
Code:
% /bin/sh                    (this enters the Bourne Shell from the C-Shell)
# while ...                  (your while)
^D                           (exit the Bourne shell; back to the C-Shell)
%
and that will work.
 
Old 04-21-2010, 11:34 AM   #6
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,563
Blog Entries: 29

Rep: Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179
Quote:
Originally Posted by casperdaghost View Post
so i am not at work right now, but you are explaining that i should be able to go

cd /bin/sh ; while [ 1 ] ; do ps auxwww | grep fire | wc -l ; done

right from the csh command line - that would be acceptable.
No -- the technique given was to run a bash script, not to execute bash commands. If you want to be able to execute bash commands like that you need to do as you wrote "before i write a shell script to complete a task, i have to type sh or bash at the prompt, hit enter and then configure the script. then when i am done, hit control -d to get out the bash or sh shell". But there may be some misunderstanding; "writing a shell script" is creating a file with shell commands in it and then running the file as a script, thus running the commands in it. When you write "configure the script", do you mean entering commands at the prompt or creating a file with shell commands in it?
 
Old 04-22-2010, 06:12 AM   #7
casperdaghost
Member
 
Registered: Aug 2009
Posts: 348

Original Poster
Rep: Reputation: 16
i mean entering commands at the prompt.

yeah, please don't work to hard on this. just figured i would give it a shot.

alot of times when i am running a job that does not exit cleanly, i will log in to another shell and type this in directly into the command line -
while [ 1 ] do ; ps auxwww | grep somejobUncleanExit | wc -l ; date; sleep 5; done
this will return a one or a zero - which lets me know, within 5 seconds when the job is done.

i can't run this from the csh shell - i have to type in "sh" first then hit <enter>, then type in the command.

so this is not a text file that I run ./fromTheDirectory, it is just something that i type into the command line.

i do this at least 40 times a night. i don't have permissions to save anything to many of these drives.

typing the sh, switching to the bash shell is not a big hassle - I was just wondering if there was a way i could do this from the csh shell.

sure i cold just use the sh shell - but for some reason the bourne shell 'pwd' does not distinguish from a local or an NFS mounted drive. the csh shell does - and running a NFS job on a local machine is bad. so what i have is a bunch of sh shells open with the csh paths as xterm --title's, spitting out 1's or 0's. it is cluttered, but i guess that it is going to have to due, because there does not seem to be any way to type in and execute a sh command at the csh prompt.
 
  


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
Scripts run fine on *NIX/csh, but fail on Linux/tcsh? b1f30 Programming 3 12-09-2008 09:44 AM
executing CGI scripts from command line mcnscott Programming 7 08-01-2007 09:08 PM
php command line scripts naflan Programming 5 11-09-2004 09:02 AM
Change kde theme & wallpaper from command line or start scripts? JHuizingh Linux - Software 2 12-11-2003 07:44 PM
Command to list line length of multiple scripts Tekime Linux - General 2 09-06-2002 02:04 AM


All times are GMT -5. The time now is 06:08 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