Linux Classroom notes 25/may/2026

Cron Job

Reference: https://crontab.guru/

Sample Script (sample.sh):

#!/bin/bash

name="dev"
echo "$name" >> /tmp/demo.txt

Add Execute Permission

chmod +x sample.sh

Schedule with Crontab

crontab -e

Add the following line with your desired cron expression:

* * * * *  /root/sample.sh

This runs sample.sh every minute. Adjust the expression as needed using crontab.guru.

Cron Expression Format

* * * * *  command
│ │ │ │ │
│ │ │ │ └── Day of week  (0–7, Sun=0 or 7)
│ │ │ └──── Month        (1–12)
│ │ └────── Day of month (1–31)
│ └──────── Hour         (0–23)
└────────── Minute       (0–59)

Functions

#!/bin/bash

# Function with a parameter
greeting() {
    echo "Executed by user: $1"
}

greeting "devops"


# Function with local variable and return value
add() {
    local sum=$(( $1 + $2 ))
    echo "The total is: $sum"
}

add 4 6

Key Points

  • Use local inside functions to avoid polluting the global scope.
  • Pass arguments to functions using $1, $2, etc.
  • Functions must be defined before they are called.

wc (Word Count)

wc [options] filename
Flag Description
-l Count lines
-w Count words
-c Count bytes/characters
-m Count characters

Examples:

wc -l /tmp/demo.txt       # Count lines in file
wc -w sample.sh           # Count words in script
wc -c sample.sh           # Count bytes in script
wc /tmp/demo.txt          # Show lines, words, and bytes together

Leave a ReplyCancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Please turn AdBlock off
Customized Social Media Icons from Acurax Digital Marketing Agency

Discover more from Direct DevOps from Quality Thought

Subscribe now to keep reading and get access to the full archive.

Continue reading

Exit mobile version
%%footer%%