I have a shell script which does following:
- Do a scan on websites (URLS coming from all_hosts.txt),
- Get json reponse which is saved in file (outputscanner.txt)
- Run a json parser (jq) on above file and save the ouput (sslresults.csv)
- 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