0% found this document useful (0 votes)
9 views2 pages

Week 8

The document provides an overview of cron jobs, including how to create, list, and remove them in Unix-based systems. It also explains how to monitor memory consumption using the 'free' command and check remote server connectivity with the 'ping' command. Additionally, it includes a script for automating memory monitoring and connectivity checks, along with instructions for scheduling the script using cron.

Uploaded by

rakesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views2 pages

Week 8

The document provides an overview of cron jobs, including how to create, list, and remove them in Unix-based systems. It also explains how to monitor memory consumption using the 'free' command and check remote server connectivity with the 'ping' command. Additionally, it includes a script for automating memory monitoring and connectivity checks, along with instructions for scheduling the script using cron.

Uploaded by

rakesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Cron:

A cron job is a scheduled task in Unix-based operating systems that runs automatically at specified intervals. It is managed by the
cron daemon, which executes commands or scripts at predefined times or on specific schedules.

How to Use a Cron Job


• Open the Crontab
To edit the list of scheduled cron jobs, open the crontab file using:
Crontab -e
• Cron Job Syntax

• Example Cron Jobs


Run a script every day at 2:30 AM
30 2 * * * /path/to/script.sh
• List Existing Cron Jobs
crontab -l
• Remove a Cron Job
crontab -r

Monitoring memory consumption


The free command in Linux provides information about system memory usage, including RAM and swap memory. By default,
the output is displayed in kilobytes (KB) unless a specific unit is specified
Syntax:
free [options]

Option Description
-b Display memory in bytes
-k Display memory in kilobytes (default)
-m Display memory in megabytes
-g Display memory in gigabytes
--tera Display memory in terabytes
-h Display memory in human-readable format (auto-adjusts size)
-s [seconds] Continuously display memory usage every X seconds
-t Show total memory including RAM and swap
-c [count] Repeat memory display [count] times
Sample output
total used free shared buff/cache available
mem 16392340 4518232 203472 1536032 11650636 10478692
swap 2097148 0 2097148
Check remote server connectivity
The ping command is a network utility used to test the connectivity between a local machine and a remote host. It works by
sending ICMP (Internet Control Message Protocol) Echo Request packets to the target and measuring the response time.
Syntax :
ping [options] destination
Example
ping google.com
Output:
PING google.com (142.250.183.14) 56(84) bytes of data.
64 bytes from 142.250.183.14: icmp_seq=1 ttl=116 time=12.5 ms
64 bytes from 142.250.183.14: icmp_seq=2 ttl=116 time=13.0 ms
64 bytes from 142.250.183.14: icmp_seq=3 ttl=116 time=12.8 ms
...
--- google.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2003ms
rtt min/avg/max/mdev = 12.500/12.766/13.000/0.200 ms
Breakdown of the Output

Field Description
PING google.com (142.250.183.14) Resolves the domain to an IP address
64 bytes from 142.250.183.14 Packet size received from the target
icmp_seq=1 ICMP sequence number (increments with each request)
ttl=116 Time-to-live (limits packet lifespan, decrements at each hop)
time=12.5 ms Round-trip time (RTT) in milliseconds
3 packets transmitted, 3 received Number of packets sent and received
0% packet loss Shows network reliability
Minimum, average, maximum, and standard deviation of
rtt min/avg/max/mdev
response times

Script for automation of monitoring memory consumption and checking remote server
connective

Create a script and save it as mem_ser.sh with the commands


touch mem_ser.sh
Type in the code in the file created
#! /bin/bash
echo "memory consumption output in memory_output.txt"
free -h > home/Student/Desktop/memory_output.txt
echo "checking the connectivity of remote server output saved in the file ping_output.txt"
ping -c 8.8.8.8 > home/Student/Desktop/memory_output.txt
echo "End of task scheduler"
After creating the script, assign execute permission by running the following commands
chmod a+x mem_ser.sh

Scheduling the script


To schedule a job for everyday:
This can be done in t he following way by execuiting as showing below
* * * * * /home/Student/Desktop/mem_ser.sh

You might also like