LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   'uptime' bash script (https://www.linuxquestions.org/questions/linux-software-2/uptime-bash-script-40761/)

icyfire 01-08-2003 04:53 PM

'uptime' bash script
 
I'm looking to put my system uptime into my bash prompt. I checked out the Bash-Prompt-HOWTO and it showed a script the author had written. I tried to make this into a script that I could use, but bash is returning errors. I don;t know the first thing about bash programming, so could someone help find the error? Thanks!

icy

Code:

#!/bin/bash
#
#  upt - show just the system uptime, days, hours, and minutes

let upSeconds="$(cat /proc/uptime) && echo ${temp%%.*})"
let secs=$((${upSeconds}%60))
let mins=$((${upSeconds}/60%60))
let hours=$((${upSeconds}/3600%24))
let days=$((${upSeconds}/86400))
if [ "${days}" -ne "0" ]
then
  echo -n "${days}d"
fi
echo -n "${hours}h${mins}m"


niknah 01-08-2003 07:50 PM

you have to post the error message before anyone can help you.

anyways the first line looks funny, try....
upSeconds=`cat /proc/uptime`;
upSeconds=${upSeconds%%.*};

trickykid 01-08-2003 08:40 PM

If you get a "command not found" type error, most likely its just not executable. chmod +x filename

icyfire 01-10-2003 04:18 AM

Thanks so much, that really helps. I like the uptime in my prompt.

bulliver 01-10-2003 05:53 AM

I was just reading the bash-prompt how-to as well, very cool. I changed my prompt to this:

[03:50][bulliver@badcomputer bulliver]$

I have different colors for each user which helps to keep track of all the different shell sessions. Here's the PS1:

\[\033[0;35m\][$(date +%H:%M)][\u@\h \W]$\[\033[0m\]


All times are GMT -5. The time now is 12:57 AM.