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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
06-03-2014, 12:13 PM
|
#1
|
Member
Registered: Mar 2014
Distribution: Crunchbang
Posts: 44
Rep: 
|
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
|
|
|
06-03-2014, 01:32 PM
|
#2
|
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
|
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.
|
06-04-2014, 01:08 AM
|
#3
|
Member
Registered: Mar 2013
Posts: 650
Rep: 
|
You could use
Code:
p=$(route -n | grep UG | awk '{print $2}')
|
|
1 members found this post helpful.
|
06-04-2014, 01:34 AM
|
#4
|
LQ Addict
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 23,976
|
p=$(route -n | awk '/UG/{print $2}')
would be even simpler (and faster)
|
|
1 members found this post helpful.
|
06-04-2014, 09:24 AM
|
#5
|
LQ Guru
Registered: Sep 2009
Location: Perth
Distribution: Arch
Posts: 10,035
|
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.
|
06-10-2014, 09:57 PM
|
#6
|
Member
Registered: Jan 2014
Location: Gulf Coast, USA
Distribution: Xubuntu
Posts: 51
Rep: 
|
Love the scripts. Thanks for referring us to this page, Jamison!
|
|
|
All times are GMT -5. The time now is 07:29 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|