Simple CSH instance

Source: Internet
Author: User

Check whether the flag file is running or not.

Process detection that can be added with related keywords.

 

Code(Simple CSH instance) running_check

# ! /Bin/CSH-F

If ($ # Argv <2) then
Usage:
Echo " Usage: $0 <running_flag> <action> <timeout> "
Echo " Action need be one value of-check or-Delete. "
Echo " Default timeout is 0, it means no timeout limitation. "
Exit 1
Endif

Set running_flag = $ 1
Set action = $2
Set timeout = 0
If ( " $3 " ! = "" ) Set timeout = $ 3
If ( " $ Action " ! = " -Check " && " $ Action " ! = " -Delete " ) Goto Usage

# Wait until the flag is deleted by ohter processes or timeout.
Set waittime =0
If ( " $ Action " = " -Check " &-E $ Running_flag ) Then
Echo " Running flag is existed, please wait! "
Set running = 1
Set sleeptime = 60
While (( " $ Timeout " ! = " 0 " && $ Waittime < $ Timeout )&&$ Running \
| " $ Timeout " = " 0 " && $ Running )
Echo " Sleep $ sleeptime " &&Sleep $ Sleeptime
@ Waittime + = $ Sleeptime
If (! -E $ Running_flag ) Set running = 0
End
Endif

# Timeout, delete the flag.
If (" $ Timeout " ! = " 0 " && " $ Waittime " > = " $ Timeout " ) Then
Echo " Timeout $ timeout "
Echo " Delete running flag "
If (-E $ Running_flag ) Rm $ Running_flag
Endif

# If check, set new flag.
# If Delete, delete the flag.
If ( " $ Action " = " -Check " ) Then
Echo " Touch running flag "
Touch $ Running_flag
Echo 'date'> $ Running_flag
Ls-l $ Running_flag
Else
Echo " Delete running flag "
If (-E $ Running_flag ) Rm $ Running_flag
Endif
Exit 0

 

Complete!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.