I am trying to create a script for a class and I am having a problem with my user count line. I cannot figure out how to move the 2 closer to the string. Below is what it looks like and my code is below that!
[root@testit /root]# ./syswatch
Free/Total Memory : 261/320 MB
Free/Total Swap : 259/259 MB
User count is at 2
#!/bin/sh
#
# Syswatch Shows a variety of different task based on my Linux System
#
# description: This script will first check the percentage of the filesystem
# being used. If the percentage is above ___, the root user will
# be emailed. There will be 4 things echoed in this script. The
# first thing being the amount of free/total memory being used,
# second the amount of free/total swap space being used, the
# third is the user count, and the last thing is the amount
# of time that the system has been up for and the system load.
#Prints amount of Free/Total Memory and Swap
free -t -m | grep "Total" | awk '{ print "Free/Total Memory : "$4"/"$2" MB";}'
free -t -m | grep "Swap" | awk '{ print "Free/Total Swap : "$4"/"$2" MB";}'
#Displays the user count for the system
echo "User count is at `who | wc -l`"
exit 0
You can control the format well with
printf
Note that I replaced the backticks with $(). This is primarily a style decision, but many (myself included) will argue that backticks are a horrible, horrible thing best relegated to the past.