Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

Steps for Job Details Script

1. SSH to any SAS Grid Node Server


2. Switch to root user by below command and put password
sudo su –
3. Create directory with the name of of JobsDetails under the root folder by below command
Mkdir JobsDetails
4. Enter in to the newly created directory by following command
cd JobsDetails
5. Within the JobsDetails directory create a .sh file with the name of script.sh by below command
touch script.sh
6. Then open the script.sh file by running below command:
Cat > script.sh
7. Now the paste the below script within the script.sh file:

#!/bin/bash

# Log file to read


log_file="access.log"

# CSV file to create


# csv_file="/mnt/d/qais-practice/output.csv"
csv_file="output.csv"

# Email details
recipient_email="asadghalib6@gmail.com"
sender_email="asadrehmanbangash2@gmail.com"
email_subject="Log File CSV Report"
email_body="Attached is the CSV report generated from the log
file."

# Read the log file and convert it to CSV


awk '{print}' "$log_file" | tr '\t' ',' > "$csv_file"

# Check if the CSV file was created successfully


if [ -s "$csv_file" ]; then
echo "CSV file created successfully."

# Send an email with the CSV file attached


{
echo "To: $recipient_email"
echo "From: $sender_email"
echo "Subject: $email_subject"
echo "$email_body"
echo "Content-Type: attachment"
echo "Content-Disposition: attachment;
filename=\"$csv_file\""
echo
cat "$csv_file"
} | mutt -s "$email_subject" -a "$csv_file" --
"$recipient_email"
echo "Email sent successfully."
else
echo "CSV file creation failed or is empty."
fi

8. Check the file by running below command to confirm that the file is present or not
Ls –lrt
9. Now to make script.sh executable we will set permissions by running below command:
Chmod +x script.sh

10. Set the script in cron in each server by running below command:
Crontab –e and then enter i to get into insert mode, then copy and paste following lines:

For server AWSAIZNVA2223.JNJ.COM


#Job Details Monitoring Automation
15 6 ***/root/JobsDetails/script.sh

11. Enter ecp


Type :wq to save and exit
Press Enter

You might also like