- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- shell script question
Operating System - Linux
1752806
Members
6008
Online
108789
Solutions
Forums
Categories
Company
Local Language
юдл
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
юдл
back
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-28-2005 09:00 PM
тАО11-28-2005 09:00 PM
shell script question
Dear Sirs,
I saw a script running in crontab as:-
sh -c /home/bigguy/scripts/rose.sh >/dev/null 2>&1
The script rose.sh is written in korn shell.
The above script is running with "sh -c"
I don't understand the significance of "sh -c" option here.
Appreciate any suggestion.
Thanks,
Shiv
I saw a script running in crontab as:-
sh -c /home/bigguy/scripts/rose.sh >/dev/null 2>&1
The script rose.sh is written in korn shell.
The above script is running with "sh -c"
I don't understand the significance of "sh -c" option here.
Appreciate any suggestion.
Thanks,
Shiv
- Tags:
- crontab
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-28-2005 09:13 PM
тАО11-28-2005 09:13 PM
Re: shell script question
Hi Shiv,
-c means that shell reads the command from the file or from the "string". See man sh-posix for -c.
Regards,
Borislav
-c means that shell reads the command from the file or from the "string". See man sh-posix for -c.
Regards,
Borislav
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-28-2005 09:29 PM
тАО11-28-2005 09:29 PM
Re: shell script question
sh -c /home/bigguy/scripts/rose.sh means it is reading strings line by line and executing that.
You can run that script as,
# sh -c < /home/bigguy/scripts/rose.sh
Difference is as,
# sh ls
sh: ls: Execute permission denied.
# sh -c ls
...
It is reading ls as script instead of file. If you are not having -c option then it will take next argument as file name and after that as arguments.
hth.
You can run that script as,
# sh -c < /home/bigguy/scripts/rose.sh
Difference is as,
# sh ls
sh: ls: Execute permission denied.
# sh -c ls
...
It is reading ls as script instead of file. If you are not having -c option then it will take next argument as file name and after that as arguments.
hth.
Easy to suggest when don't know about the problem!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-28-2005 11:49 PM
тАО11-28-2005 11:49 PM
Re: shell script question
Hi Shivkumar,
apart from what has already been stated there is also a difference with regard to process hierarchy and number of shells; try comparing the output of
$ sh -c "ps -f"
to the output of
$ ps -f
Sample output:
$ ps -f
UID PID PPID C STIME TTY TIME COMMAND
jxk 614 20419 3 12:39:42 pts/tc 0:00 ps -f
jxk 20419 20418 0 Nov 28 pts/tc 0:01 -sh
root 20418 1163 0 Nov 28 pts/tc 0:00 telnetd
The COMMAND ps -f has PID 614; the PPID (father of ps -f) is 20419.
PID 20419 is the shell itself, -sh, in which ps is executed
PID 20418, telnetd, is the father of -sh
Simple hierarchy for the above:
telnet
sh
ps -f
However.....
$ sh -c "ps -f"
UID PID PPID C STIME TTY TIME COMMAND
jxk 619 20419 2 12:43:38 pts/tc 0:00 sh -c ps -f
jxk 20419 20418 1 Nov 28 pts/tc 0:01 -sh
root 20418 1163 0 Nov 28 pts/tc 0:00 telnetd
jxk 620 619 4 12:43:38 pts/tc 0:00 ps -f
The output order looks confusing; start at
PID 620, the ps -f command, whose father is
PID 619, the command sh -c pd -f, whose father is
PID 20419, -sh whose father is
PID 20418, telnetd
Hierarchy with extra shell layer:
telnet
sh (the already available shell)
sh (the sh -c shell, extra)
ps -f (is executed in the sh -c shell)
In the example
sh -c /home/bigguy/scripts/rose.sh >/dev/null 2>&1
sh -c creates a shell layer, like in the above example, in which rose.sh will be executed.
However, if rose.sh sh has been properly written, i.e. the first line specifying which shell to use,
sh -c
does - in my opinion - not influence how rose.sh is executed.
regards,
John K.
apart from what has already been stated there is also a difference with regard to process hierarchy and number of shells; try comparing the output of
$ sh -c "ps -f"
to the output of
$ ps -f
Sample output:
$ ps -f
UID PID PPID C STIME TTY TIME COMMAND
jxk 614 20419 3 12:39:42 pts/tc 0:00 ps -f
jxk 20419 20418 0 Nov 28 pts/tc 0:01 -sh
root 20418 1163 0 Nov 28 pts/tc 0:00 telnetd
The COMMAND ps -f has PID 614; the PPID (father of ps -f) is 20419.
PID 20419 is the shell itself, -sh, in which ps is executed
PID 20418, telnetd, is the father of -sh
Simple hierarchy for the above:
telnet
sh
ps -f
However.....
$ sh -c "ps -f"
UID PID PPID C STIME TTY TIME COMMAND
jxk 619 20419 2 12:43:38 pts/tc 0:00 sh -c ps -f
jxk 20419 20418 1 Nov 28 pts/tc 0:01 -sh
root 20418 1163 0 Nov 28 pts/tc 0:00 telnetd
jxk 620 619 4 12:43:38 pts/tc 0:00 ps -f
The output order looks confusing; start at
PID 620, the ps -f command, whose father is
PID 619, the command sh -c pd -f, whose father is
PID 20419, -sh whose father is
PID 20418, telnetd
Hierarchy with extra shell layer:
telnet
sh (the already available shell)
sh (the sh -c shell, extra)
ps -f (is executed in the sh -c shell)
In the example
sh -c /home/bigguy/scripts/rose.sh >/dev/null 2>&1
sh -c creates a shell layer, like in the above example, in which rose.sh will be executed.
However, if rose.sh sh has been properly written, i.e. the first line specifying which shell to use,
sh -c
does - in my opinion - not influence how rose.sh is executed.
regards,
John K.
it would be nice if you always got a second chance
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
News and Events
Support
© Copyright 2024 Hewlett Packard Enterprise Development LP