0% found this document useful (0 votes)
14 views3 pages

To Automate The Process of Running The

The document provides a step-by-step guide to automate the execution of the `bjobs -u all` command, convert the output to a CSV file, and email it daily using a shell script and cron job. It includes instructions on creating the script, making it executable, and scheduling it with cron. Additionally, it outlines deployment steps for setting up the script on a server, including file creation and editing commands.

Uploaded by

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

To Automate The Process of Running The

The document provides a step-by-step guide to automate the execution of the `bjobs -u all` command, convert the output to a CSV file, and email it daily using a shell script and cron job. It includes instructions on creating the script, making it executable, and scheduling it with cron. Additionally, it outlines deployment steps for setting up the script on a server, including file creation and editing commands.

Uploaded by

asad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

To automate the process of running the `bjobs -u all` command, retrieving the data from the server,

converting it to a CSV file, and sending it via email on a daily basis, you can create a shell script and use a
scheduler like `cron` to run it daily. Here's a step-by-step guide on how to do this:

1. **Create a Shell Script**:

Create a new shell script file, for example, `job_status_report.sh`, using a text editor:

```bash

nano job_status_report.sh

```

2. **Write the Script**:

Inside the script file, you can use the following code to run the `bjobs -u all` command, save the output
to a CSV file, and send it via email using the `mail` command:

```bash

#!/bin/bash

# Run the bjobs command and save the output to a CSV file

bjobs -u all > job_status.csv

# Email the CSV file as an attachment

recipient_email="[email protected]"

sender_email="[email protected]"

subject="Daily Job Status Report"

body="Attached is the daily job status report."

mail -s "$subject" -a job_status.csv -r "$sender_email" "$recipient_email" <<< "$body"


# Cleanup: Remove the temporary CSV file

rm job_status.csv

```

Make sure to replace `[email protected]` and `[email protected]` with the actual email
addresses you want to use.

3. **Make the Script Executable**:

Save the file and make it executable using the following command:

```bash

chmod +x job_status_report.sh

```

4. **Set Up Cron Job**:

Use `cron` to schedule the script to run daily. Open your crontab configuration:

```bash

crontab -e

```

Add the following line to run the script every day at a specific time (e.g., 9 AM):

```bash

0 9 * * * /path/to/job_status_report.sh

```
Replace `/path/to/` with the actual path to your script.

5. **Save and Exit**:

Save your crontab configuration and exit the text editor.

Now, your script will run the `bjobs -u all` command, save the output to a CSV file, and email it as an
attachment every day at the specified time. Make sure your server has `mail` or another mail client
configured for sending emails.

Note: Ensure that the server where you're running this script has the necessary permissions to execute
`bjobs`, create files, and send emails. Also, consider setting up proper email authentication and error
handling in your script for production use.

***********************************************************************************

Deployment Steps

1. I logged in to the QA server awsaiznva2223.jnj.com (SAS Grid QA Node 1) as a root user [sudo su
-]
2. Create a directory by using mkdir [name of directory] command.
3. Enter to the directory by using cd [name of directory] command
4. Create a file inside a directory by using touch [name_of_file.sh] command
5. We use ls command to see if the file is created.
6. To edit the newly created file we use vim [name_of_file.sh] command and then press I from
keyboard to insert code into the file, then we can paste our script which is copied from visual
studio.
7. Press Esc button from the keyboard and type :wq then press enter button to save the file.
8. To run our script we can use following command
./ [name_of_file.sh]

You might also like