I am a beginner at scripting but I’m trying to make a shell script called monitornsusystem.sh that will append system related information to the file: systemstatus.log. This system information I need to append is: current date and time, CPU utilization as a percentage and system memory in use as a percentage. I can get all the right information from individual commands but when I put them together in a script, it’s not working the way I planned.

sysstat=echo “date +'%d/%m/%Y %H:%M:%S' | echo $[100-$(vmstat 1 2|tail -1|awk '{print $15}’)]% | free | grep Mem | awk '{print $3/$2 * 100.0}’” >> systemstatus.log
  • 2
    In what way is it not 'working as planned'? I see a couple of potential issues with the command you posted, but it would be useful to know specifics. – bertieb Feb 25 '17 at 13:03
  • Those characters look a bit like double-quotes ", but they are different. That really won't help. – Toby Speight Mar 1 '17 at 16:14

Without more details I just can figure out that your desired command and output could be:

echo -n $(date +'%d/%m/%Y %H:%M:%S')" " && echo -n $(vmstat 1 2 | tail -1 | awk '{print $15}')" " && echo $(free | grep Mem | awk '{print $3/$2 * 100.0}')

Which would provide:

27/02/2017 12:40:47 99 78.2968

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.