LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 04-11-2023, 06:13 AM   #16
sag2662
Member
 
Registered: Sep 2022
Posts: 74

Original Poster
Rep: Reputation: 0

Quote:
Originally Posted by pan64 View Post
does this machine run continuously?
yes it is
 
Old 04-11-2023, 06:15 AM   #17
sag2662
Member
 
Registered: Sep 2022
Posts: 74

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by michaelk View Post
Without knowing what command actually does it is not possible to know whats wrong. How long does it take to actually run the it once? If it takes more then a minute to run the command 12 times you will have multiple processes which continue into the next day. You are also missing the sleep 5 command in your loop.
I am just running ping -c hostname
 
Old 04-11-2023, 07:44 AM   #18
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,759

Rep: Reputation: 5930Reputation: 5930Reputation: 5930Reputation: 5930Reputation: 5930Reputation: 5930Reputation: 5930Reputation: 5930Reputation: 5930Reputation: 5930Reputation: 5930
What is the count value for -c?
 
Old 04-11-2023, 08:01 AM   #19
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,962

Rep: Reputation: 7332Reputation: 7332Reputation: 7332Reputation: 7332Reputation: 7332Reputation: 7332Reputation: 7332Reputation: 7332Reputation: 7332Reputation: 7332Reputation: 7332
probably you can find something in the log of cron
additionally you may try to create your own log about the executions.
 
Old 04-11-2023, 08:56 AM   #20
sag2662
Member
 
Registered: Sep 2022
Posts: 74

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by michaelk View Post
What is the count value for -c?
ping -c 1 hostname
 
Old 05-15-2023, 02:22 AM   #21
sag2662
Member
 
Registered: Sep 2022
Posts: 74

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by pan64 View Post
does this machine run continuously?
yes is it possible to schedule cronjob for every second
 
Old 05-15-2023, 05:09 AM   #22
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,759

Rep: Reputation: 5930Reputation: 5930Reputation: 5930Reputation: 5930Reputation: 5930Reputation: 5930Reputation: 5930Reputation: 5930Reputation: 5930Reputation: 5930Reputation: 5930
Code:
/etc/systemd/system/mytimer.service:
[Unit]
Description=my timer service
[Service]
User=my_name
ExecStart=/home/username/script.sh

/etc/systemd/system/mytimer.timer:
[Unit]
Description=my_timer timer

[Timer]
OnUnitActiveSec=5s
OnBootSec=5s

[Install]
WantedBy=timers.target
 
Old 05-15-2023, 11:43 PM   #23
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,363

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Quote:
is it possible to schedule cronjob for every second
answer : No - see my prev post #10
 
Old 05-16-2023, 01:54 AM   #24
sag2662
Member
 
Registered: Sep 2022
Posts: 74

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by chrism01 View Post
answer : No - see my prev post #10
nohup is creating bulk requests and I dont want to use it. My goal is to run continous ping checks between two hosts, so if any packetloss is there it should be reported in the logs.

Code:
for ((i=0; i<12; i++))
do
ping -c 10 $host | grep "packet loss" 
sleep 1
done


cronjob * * * * * sh /home/ping.sh
this runs every 5 or 6 seconds seconds, how to run it for each second ?

Last edited by sag2662; 05-16-2023 at 02:48 AM.
 
Old 05-16-2023, 01:59 AM   #25
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,962

Rep: Reputation: 7332Reputation: 7332Reputation: 7332Reputation: 7332Reputation: 7332Reputation: 7332Reputation: 7332Reputation: 7332Reputation: 7332Reputation: 7332Reputation: 7332
man sleep?
 
Old 05-16-2023, 03:05 AM   #26
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,807

Rep: Reputation: 1207Reputation: 1207Reputation: 1207Reputation: 1207Reputation: 1207Reputation: 1207Reputation: 1207Reputation: 1207Reputation: 1207
Quote:
Originally Posted by sag2662 View Post
nohup is creating bulk requests and I dont want to use it. My goal is to run continous ping checks between two hosts, so if any packetloss is there it should be reported in the logs.

Code:
for ((i=0; i<12; i++))
do
ping -c 10 $host | grep "packet loss" 
sleep 1
done


cronjob * * * * * sh /home/ping.sh
so this mean now the ping checks will be every second.
You do not need a loop or sleep.
The following does everything with one ping:
Code:
#!/bin/sh
host="localhost"
ping -n -i 2 -c 29 -w 60 $host >/dev/null || echo "alert: $host did not respond"
-n no hostname lookups
-i 2 every 2 seconds
-c 29 ping samples
-w 60 seconds total timeout

Or set a 1 second per-ping timeout:
Code:
ping -n -i 2 -c 29 -W 1 $host >/dev/null || echo "alert: $host did not respond"

Last edited by MadeInGermany; 05-17-2023 at 02:29 AM.
 
Old 05-01-2024, 10:14 AM   #27
murugesandins
Member
 
Registered: Apr 2024
Location: Bangalore Karnataka India
Distribution: CYGWIN_NT
Posts: 75

Rep: Reputation: 1
sample service at windows using CYGWIN_NT

Due to your query I have installed cron at windows using CYGWIN_NT and started cron service.
1. Create a shell script file
Example:
Code:
$ cat /home/murugesandins/mycron.sh
#!/bin/bash
/usr/bin/date "+%a %d-%b-%Y %I:%M:%S %p %Z" >> /tmp/output.txt
$ chmod +x /home/murugesandins/mycron.sh
Create cron job
Code:
$ crontab -e
Add following lines:
Code:
#There is no option to mention seconds. Hence use sleep... to execute at related timings
#Minute Hour DayOfMonth MonthOfYear DayOfWeek Create six cron job to execute at each 10 seconds.
      *    *          *           *         * ( /usr/bin/sleep 10;/home/murugesandins/mycron.sh )
      *    *          *           *         * ( /usr/bin/sleep 20;/home/murugesandins/mycron.sh )
      *    *          *           *         * ( /usr/bin/sleep 30;/home/murugesandins/mycron.sh )
      *    *          *           *         * ( /usr/bin/sleep 40;/home/murugesandins/mycron.sh )
      *    *          *           *         * ( /usr/bin/sleep 50;/home/murugesandins/mycron.sh )
      *    *          *           *         * ( /usr/bin/sleep 60;/home/murugesandins/mycron.sh )
Save and quit
Each 10/20/30/40/50/60 seconds the output written at /tmp/output.txt
Example:
Code:
$ cat /tmp/output.txt
Wed 01-May-2024 08:38:11 PM IST
Wed 01-May-2024 08:38:21 PM IST
Wed 01-May-2024 08:38:31 PM IST
Wed 01-May-2024 08:38:41 PM IST
Wed 01-May-2024 08:38:51 PM IST
Wed 01-May-2024 08:39:01 PM IST
Wed 01-May-2024 08:39:11 PM IST
Wed 01-May-2024 08:39:21 PM IST
Wed 01-May-2024 08:39:31 PM IST
Wed 01-May-2024 08:39:41 PM IST
Wed 01-May-2024 08:39:51 PM IST
Wed 01-May-2024 08:40:01 PM IST
Wed 01-May-2024 08:40:12 PM IST
Wed 01-May-2024 08:40:22 PM IST
Wed 01-May-2024 08:40:32 PM IST
Wed 01-May-2024 08:40:42 PM IST
Wed 01-May-2024 08:40:52 PM IST
Wed 01-May-2024 08:41:02 PM IST
Wed 01-May-2024 08:41:11 PM IST
Wed 01-May-2024 08:41:21 PM IST
Wed 01-May-2024 08:41:31 PM IST
Code:
$ crontab -l
# DO NOT EDIT THIS FILE - edit the master and reinstall.
# (/tmp/crontab.1ohnI6c1ek installed on Wed May  1 20:32:21 2024)
# (Cron version V5.0 -- $Id: crontab.c,v 1.12 2004/01/23 18:56:42 vixie Exp $)
#Minute Hour DayOfMonth MonthOfYear DayOfWeek Create six cron job to execute at each 10 seconds.
      *    *          *           *         * ( /usr/bin/sleep 10;/home/murugesandins/mycron.sh )
      *    *          *           *         * ( /usr/bin/sleep 20;/home/murugesandins/mycron.sh )
      *    *          *           *         * ( /usr/bin/sleep 30;/home/murugesandins/mycron.sh )
      *    *          *           *         * ( /usr/bin/sleep 40;/home/murugesandins/mycron.sh )
      *    *          *           *         * ( /usr/bin/sleep 50;/home/murugesandins/mycron.sh )
      *    *          *           *         * ( /usr/bin/sleep 60;/home/murugesandins/mycron.sh )
$ crontab -r
$ crontab -l
no crontab for murugesandins
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
video repeats 0.5 seconds every 60 seconds WilliamTexelHampton Linux - Newbie 6 06-29-2017 11:10 AM
cronjob to run every 15 minutes? your_shadow03 Linux - Newbie 5 11-19-2009 10:58 PM
[SOLVED] Experiencing freezing up to 5 seconds every 10 seconds, could these be the problem? Switch7 Slackware 10 11-16-2009 04:36 PM
how do i get a cronjob to run every two hours in AIX: 00 */2 * * * command no work boyd98 AIX 1 10-19-2009 06:33 PM
[SOLVED] make cronjob run every 10mins qwertyjjj Linux - Newbie 2 08-13-2009 08:06 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 09:56 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration