• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

unix scripting

 
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author and jackaroo
Posts: 12200
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 12200
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic