LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 06-03-2014, 12:13 PM   #1
Train
Member
 
Registered: Mar 2014
Distribution: Crunchbang
Posts: 44

Rep: Reputation: Disabled
Post n00b scripting


Just playing around. I made this simple script to report things about the system.

And the 2nd script for printing the output to a physical printer.

[It works. This thread does not involve any direct questions.]

Code:
#!/bin/bash
# This script is for a system reporting.

echo "_____________"
echo -n "SYSTEM REPORT"
echo ""
echo "_____________"
echo -n "SYSTEM REPORT"
echo ""
echo "_____________"
echo -n "SYSTEM REPORT"
echo ""
echo "_____________"
echo ""
echo ""
echo "--------------------------------------------------"
echo -n "DATE and TIME:"
echo ""
echo "--------------------------------------------------"
date
echo ""
echo ""
echo "--------------------------------------------------"
echo -n "HOSTNAME:"
echo ""
echo "--------------------------------------------------"
hostname
echo ""
echo ""
echo "--------------------------------------------------"
echo -n "Up Time:"
echo ""
echo "--------------------------------------------------"
uptime
echo ""
echo ""
echo "--------------------------------------------------"
echo -n "LSB Version:"
echo ""
echo "--------------------------------------------------"
lsb_release -a
echo ""
echo ""
echo "--------------------------------------------------"
echo -n "Kernel Version:"
echo ""
echo "--------------------------------------------------"
uname -r
echo ""
echo ""
echo "--------------------------------------------------"
echo -n "Disk Usage:"
echo ""
echo "--------------------------------------------------"
df -h
echo ""
echo ""
echo -n "FSTAB:"
echo ""
cat /etc/fstab
echo ""
echo ""
echo -n "MTAB:"
echo ""
cat /etc/mtab
echo ""
echo ""
echo "--------------------------------------------------"
echo -n "CPU Information: "
echo ""
echo "--------------------------------------------------"
cat /proc/cpuinfo
echo ""
echo ""
echo "--------------------------------------------------"
echo -n "Memmory Information: "
echo ""
echo "--------------------------------------------------"
cat /proc/meminfo
echo ""
echo ""
echo "--------------------------------------------------"
echo -n "Networking Information: "
echo ""
echo "--------------------------------------------------"
ifconfig
route -n
#IP Ping
p=$(route -n | grep UG | tr -s " " | cut -f 2 -d " ")
pp="/bin/ping"
echo ""
echo "Checking to see if $p is up..."
echo ""
$pp -c 2 $p
echo ""
echo ""
echo "--------------------------------------------------"
echo -n "PCI Devices:"
echo ""
echo "--------------------------------------------------"
lspci
echo ""
echo ""
echo "____________________"
echo "END OF SYSTEM REPORT"
echo "____________________"
echo -n "END OF SYSTEM REPORT"
echo ""
echo "____________________"
echo -n "END OF SYSTEM REPORT"
echo ""
echo "____________________"
Code:
#!/bin/bash
echo "----------------------------------------------------"
echo -n "Printing System Report"
echo ""
echo "----------------------------------------------------"
echo -n "Which lp printer? (hplj) "
read device
: ${device:="hplj"}
./sr | lp -o scaling=100 -d $device
 
Old 06-03-2014, 01:32 PM   #2
jamison20000e
Senior Member
 
Registered: Nov 2005
Location: ...uncanny valley... infinity\1975; (randomly born:) Milwaukee, WI, US( + travel,) Earth&Mars (I wish,) END BORDER$!◣◢┌∩┐ Fe26-E,e...
Distribution: any GPL that work on freest-HW; has been KDE, CLI, Novena-SBC but open.. http://goo.gl/NqgqJx &c ;-)
Posts: 4,888
Blog Entries: 2

Rep: Reputation: 1567Reputation: 1567Reputation: 1567Reputation: 1567Reputation: 1567Reputation: 1567Reputation: 1567Reputation: 1567Reputation: 1567Reputation: 1567Reputation: 1567
Hi. I'm new to it as well, just some ideas (mostly links while I play:)

formatting from bash instead of
Code:
echo "_____________"
you could try making a variable or function to something like
Code:
NL=$(printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' _)
echo $NL
http://wiki.bash-hackers.org/snipple...orizontal_line
http://www.cplusplus.com/reference/cstdio/printf/
http://wiki.bash-hackers.org/scripting/style

looks fun good tools too, thanks.
 
2 members found this post helpful.
Old 06-04-2014, 01:08 AM   #3
eklavya
Member
 
Registered: Mar 2013
Posts: 650

Rep: Reputation: 145Reputation: 145
You could use
Code:
p=$(route -n | grep UG | awk '{print $2}')
 
1 members found this post helpful.
Old 06-04-2014, 01:34 AM   #4
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 23,976

Rep: Reputation: 7887Reputation: 7887Reputation: 7887Reputation: 7887Reputation: 7887Reputation: 7887Reputation: 7887Reputation: 7887Reputation: 7887Reputation: 7887Reputation: 7887
p=$(route -n | awk '/UG/{print $2}')
would be even simpler (and faster)
 
1 members found this post helpful.
Old 06-04-2014, 09:24 AM   #5
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Arch
Posts: 10,035

Rep: Reputation: 3202Reputation: 3202Reputation: 3202Reputation: 3202Reputation: 3202Reputation: 3202Reputation: 3202Reputation: 3202Reputation: 3202Reputation: 3202Reputation: 3202
You could try using a heredoc to save on the high usage of echo, here is a small example:
Code:
cat <<EOF
_____________
SYSTEM REPORT

_____________
SYSTEM REPORT

_____________
SYSTEM REPORT

_____________


--------------------------------------------------
DATE and TIME:

--------------------------------------------------
$(date)


--------------------------------------------------
HOSTNAME:

--------------------------------------------------
$(hostname)
EOF
 
1 members found this post helpful.
Old 06-10-2014, 09:57 PM   #6
l33y
Member
 
Registered: Jan 2014
Location: Gulf Coast, USA
Distribution: Xubuntu
Posts: 51
Blog Entries: 1

Rep: Reputation: Disabled
Love the scripts. Thanks for referring us to this page, Jamison!
 
  


Reply


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Scripting the Linux desktop, Part 2: Scripting Nautilus LXer Syndicated Linux News 0 02-17-2011 04:02 AM
Firefox Scripting Add-on (Scripting HTML / Javascript inside Firefox) linuxbeatswindows Programming 1 09-18-2009 10:09 PM
n00b scripting nakedmoses Programming 3 05-25-2007 09:30 AM
teaching shell scripting: cool scripting examples? fax8 Linux - General 1 04-20-2006 04:29 AM
N00b in need (is n00b indeed) MainframeGuy Linux - Wireless Networking 2 12-10-2004 12:36 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 07:29 AM.

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