Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8922485
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T06:50:53+00:00 2026-06-15T06:50:53+00:00

I have below code in my shell script which will keep on sleeping if

  • 0

I have below code in my shell script which will keep on sleeping if it doesn’t finds any file. And it sleeps for half an hour but currently I don’t have any counter like only execute the below code 20 times and then exit the program if the files are still are not there (means don’t do anything after 20 checks and exit the full script).

What’s the best way to do this problem? So that I am also aware by looking at the emails that it has tried 20 times.

Hope I am clear enough.

while true; do
  if /home/hadoop/latest/bin/hadoop fs -ls /apps/hdtech/bds/quality-rt/dt=$DATE_YEST_FORMAT2 then
       echo "Files Present" | mailx -s "File Present"  -r admin@host.com admin@host.com
       break
  else
       echo "Sleeping for half an hour" | mailx -s "Time to Sleep Now"  -r admin@host.com admin@host.com
       sleep 1800
  fi
done
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T06:50:55+00:00Added an answer on June 15, 2026 at 6:50 am

    Here’s how you might implement a counter:

    counter=0
    while true; do
      if /home/hadoop/latest/bin/hadoop fs -ls /apps/hdtech/bds/quality-rt/dt=$DATE_YEST_FORMAT2 then
           echo "Files Present" | mailx -s "File Present"  -r admin@host.com admin@host.com
           exit 0
      elif [[ "$counter" -gt 20 ]]; then
           echo "Counter: $counter times reached; Exiting loop!"
           exit 1
      else
           counter=$((counter+1))
           echo "Counter: $counter time(s); Sleeping for another half an hour" | mailx -s "Time to Sleep Now"  -r admin@host.com admin@host.com
           sleep 1800
      fi
    done
    

    Some Explanations:

    • counter=$((counter+1)) – this is how you can increment a counter. The $ for counter is optional inside the double parentheses in this case.
    • elif [[ "$counter" -gt 20 ]]; then – this checks whether $counter is not greater than 20. If so, it outputs the appropriate message and breaks out of your while loop.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a shell script (.sh) to extract a tar file. Below is
I have below code.The logic here is if HostList conatains any blanck entry it
I have below code which overrides equals() and hashcode() methods. public boolean equals(Object obj)
I have a shell script which has a for loop that prints the value
I have sample code as below import org.codehaus.groovy.control.CompilerConfiguration abstract class MyClass extends Script {
I have below code: <a href=# id=@item.Id name=vote ><img src=/Content/images/021.png style=float:left alt= /></a> which
I have below code: class Program { static void Main(string[] args) { Task[] tasks
I have below code in html. <li class=selected runat=server id=lihome><a href=/ISS/home.aspx title=Home><span>Home</span></a></li> Now I
I have below code behind in c# if (Session[cmpDictionaryTitle]!= null) { downloadLinks.Text += @<li><a
I have below code to insert a style into DOM (there is a use

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.