Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 01-08-2003, 05:53 PM   #1
Registered: Feb 2002
Location: Bay Area, California
Distribution: Ubuntu
Posts: 110

Rep: Reputation: 15
'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!


#   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" ]
   echo -n "${days}d"
echo -n "${hours}h${mins}m"
Old 01-08-2003, 08:50 PM   #2
Registered: Dec 2002
Location: In front of a computer
Distribution: UPS, DHL, FedEx
Posts: 466

Rep: Reputation: 38
you have to post the error message before anyone can help you.

anyways the first line looks funny, try....
upSeconds=`cat /proc/uptime`;
Old 01-08-2003, 09:40 PM   #3
LQ Guru
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 235Reputation: 235Reputation: 235
If you get a "command not found" type error, most likely its just not executable. chmod +x filename
Old 01-10-2003, 05:18 AM   #4
Registered: Feb 2002
Location: Bay Area, California
Distribution: Ubuntu
Posts: 110

Original Poster
Rep: Reputation: 15
Thanks so much, that really helps. I like the uptime in my prompt.
Old 01-10-2003, 06:53 AM   #5
Senior Member
Registered: Nov 2002
Location: Edmonton AB, Canada
Distribution: Gentoo x86_64; Gentoo PPC; FreeBSD; OS X 10.9.4
Posts: 3,760
Blog Entries: 4

Rep: Reputation: 78
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\]


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Linux uptime script.. billeman Linux - Software 1 09-19-2005 12:11 PM
send automatic input to a script called by another script in bash programming jorgecab Programming 2 04-01-2004 01:20 AM
uptime in bash prompt dekket Linux - Software 3 10-07-2003 01:39 PM
bash script - incrementing a filename in a script tslinux Programming 10 08-06-2003 12:58 AM
bash script prob: how can i tell the script that a 'dd' has finished? Frustin Linux - General 2 04-02-2003 06:34 AM > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 06:44 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration