• Post Reply Bookmark Topic Watch Topic
  • New Topic

unix scripting  RSS feed

 
Sham Jowsaki
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I am new to unix shell scripting n wanna to create a unix scripting which has following functionality
There are applications runnin in my server, using status.sh script i can check whether
the application is runnin or not. if it is running it will display "xyz is running" otherwise
"xyz not found".
I have the scripts for status.sh, start.sh n stop.sh
Depends upon the above output i need to start the application or skip the step. this is for multiple application.
Can u please provide me a sample unix scripting..
Thanks
Jowsaki
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Posts: 12156
256
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jowsaki
Here is one way to do it. I am going to build this up step by step...
I assume that when you run your script, it gives you something you can look for. Eg. the text "... is running" (or the alternative "... is not running") or something similar.

If so, you can pipe the output of your first script through grep to look for your specific text.

We could use this directly with the "-z" option of test in a script. -z will test if you are testing against a zero length string:

Note the spaces after the test start indicator ([) and before the end indicator (]). Also the backwards quotation mark "`" around the command that I am running.
Personally I dont like the test for zero length strings. A slight variation would be to tell grep to return a count of how many times it found the "is running string":

You can now use the -eq, -ne, -gt, -lt operators (equal, not equal, greater than, and less than) in your tests:

Some final notes:
I used a relative path name in my examples (./myScriptCheck). For an automated script, you should always use a fully qualified path name (/home/andrewm/myScriptCheck). Do not assume that the script you are running is in your path - the path may change. It is also a security risk.
Regards, Andrew
 
Sham Jowsaki
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Many thanks Andrew, your stuff is useful. can you pls provide the unix best online tutorial to study more.
Thanks
jowskai
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Posts: 12156
256
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry Sham, I have been working with Unix and Linux systems for more years than I wish to recount, so I learnt without the benefit of web tutorials.
I think you can find some good tutorials on LinuxGuruz.
Although designed for a completely different purpose (system adminstrators changing from one Unix variant to another) the Rosetta Stone for Unix can be very useful in trying to determine what command will let you do a particular task.
Regards, Andrew
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!