Quantcast
Channel: Question and Answer » cron
Viewing all articles
Browse latest Browse all 165

Issues with a cron script

$
0
0

I have a shell script which does following:

  1. Do a scan on websites (URLS coming from all_hosts.txt),
  2. Get json reponse which is saved in file (outputscanner.txt)
  3. Run a json parser (jq) on above file and save the ouput (sslresults.csv)
  4. Email above file

I can run the script fine manually but it won’t work with cron. I only get empty csv file in email. I am currently root on the system. Linux is KaliLinux (a debian clone)

Crontab entry looks like

*/45 * * * * /root/myuser/scanner/scanner-scan-stable/script.sh

Following is my small script.

#!/bin/bash

#Date functions
getDate=$(date +"%d/%m/%Y")
dirPath=/root/myuser/scanner/scanner-scan-stable

/usr/bin/scanner-scan -quiet=true -hostfile=$dirPath/all_hosts.txt > $dirPath/outputscanner.txt

/bin/jq -c '.[] | if (.xpoints != null) then {Host:.host,Status:.xpoints[0].statusMessage,Grade:.xpoints[0].grade} else {Host:.host,Status:.statusMessage,Grade:""} end' $dirPath/outputscanner.txt | /bin/json2csv -k Host,Status,Grade -p true | /bin/csvsort -r -c Grade > $dirPath/sslresults.csv 

/usr/bin/sendemail -f test@anydomain.com -t mk@anydomain.com -u "Scanner Report $getDate" -m "Scanner Report generated on $getDate" -a $dirPath/sslresults.csv -s emailserver.anydomain.com

Viewing all articles
Browse latest Browse all 165

Trending Articles