Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

Bash script not working right


  • Please log in to reply
15 replies to this topic

#1 Ray Parrish

Ray Parrish

  • Members
  • 91 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Cottage Grove, Oregon
  • Local time:04:37 AM

Posted 03 November 2008 - 09:35 PM

Hello,

I'm on Ubuntu 8.04 and have written a script which generates a System Report in the form of a framed set of web pages. This script works perfectly on my system, but on a friend of mine's computer [who lives in another state far away] it is tossing errors for some mad reason.

Here is the error message we got on the first attempt to run it from terminal -

bash: /home/adminmandi/Desktop/SystemReport.sh: /bin/bash^M: bad interpreter: No such file or directory

The file was on her desktop when we ran it and the command used to run it in terminal was

~/Desktop/SystemReport.sh

I'm wondering where the ^M in the error message is coming from???

So, I then had her do the following in Terminal

cd ~/Desktop
SystemReport.sh

This time it returned the following

adminmandi@Ub-desktop:~$ cd ~/Desktop
adminmandi@Ub-desktop:~/Desktop$ SystemReport.sh
bash: SystemReport.sh: command not found

It's like her system can't see the script file! She's using Ubuntu 8.04 just like me.

Again, this file runs perfectly on my system. Has anyone got any idea what is causing this?

OH! I guess I should paste the code from the script in here too, here it is.

# the username of the logged on user. This set of files will load
# via home/username/SysReport/index.html a frame set with navigation in the left frame,
# and individual reports about different parts of the system in the right frame of the document.
#
#
#First we create the folder if it doesn't already exist
echo "Creating SysReport Folder"
if [ -e ~/SysReport ] && [ -d ~/SysReport ]
then _linenums:0'>#!/bin/bash## System Report Script, Version 1.05## The purpose of this script is to use shell commands to build a set of html files in a# folder in the user's folder called home/username/SysReport where username is replaced with# the username of the logged on user. This set of files will load# via home/username/SysReport/index.html a frame set with navigation in the left frame,# and individual reports about different parts of the system in the right frame of the document.###First we create the folder if it doesn't already existecho "Creating SysReport Folder"if [ -e ~/SysReport ] && [ -d ~/SysReport ] then : # if it exists and is a folder do nothing else mkdir ~/SysReportfi# Next we want to create the index.html file whether it exists or not to allow for updating it# with new versions of the scriptecho "Creating index.html"cat > ~/SysReport/index.html << EOF<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN"><HTML><HEAD> <META HTTP-EQUIV="Content-Type" CONTENT="text/html;CHARSET=iso-8859-1"> <META NAME="Author" Content="Ray Parrish"> <TITLE>System Report</TITLE></HEAD><FRAMESET COLS = "21%,79% " > <FRAME SRC="navigate.html" NAME="Navigate" RESIZE> <FRAME SRC="Introduction.html" NAME="Modules" RESIZE></FRAMESET><NOFRAMES><BODY><P></BODY></NOFRAMES></HTML>EOF#echo "Creating Introduction.html"# Here I create the introduction page.cat > ~/SysReport/Introduction.html << EOF<html><head><meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type"><title>Introduction to System Report</title></head><body><center><p>Welcome, you are logged in as: $USER</center><table style="text-align: left; width: 100%;" border="2" cellpadding="2"cellspacing="2"><tbody><tr><tdstyle="vertical-align: top; background-color: rgb(153, 255, 255);">Welcometo the script generatedSystem Report for Ubuntu systems. Thisset of web pages is generated from many accessible files and commandson yoursystem by the SystemReport.sh file. This set of pages was generated by Version 1.05 of SystemReport.sh<br><br>Each report is listed in the navigation frame on the left and will loadin this frame. Each section includes an explanation of whatcommand or file was accessed to generate that section of the report.<br><br>As I learn more about Ubuntu and Linux and scripting theSystemReport.sh file will grow and so will the number of html files itgenerates. Look for it at <a href="http://www.rayslinks.com/scripts/SysReport.html" target="blank">System Report Script</a> to see if there are newversions of it.<br><br>The SystemReport.sh file is open source and so I encourage you to addto it yourself as long as you don't hold me responsible for any damagesyour changes cause. 8-)<br><br>If you do add a section to one of the pages, or even a whole page to the set, please <a href="mailto:crp@cmc.net?subject=System Report changes">email me</a> your changes or additions only. Please don't send me the whole script to look through for your changes.<p>SystemReport.sh may be ran multiple times so that it may update thesepages when you make changes to your system and so you can replace itwith a newer version of the script and generate a new set of these webpages.<br></td></tr></tbody></table><br><br></body></html>EOF## Now it's time to create navigate.html which will expand as new parts of the script are createdecho "Creating navigate.html"cat > ~/SysReport/navigate.html << EOF<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head><title>Sysytem Report Navigation</title><meta http-equiv="Content-Type" content="text/html;CHARSET=iso-8859-1"> <meta content="Ray Parrish" name="Author"></head><body><ul> <li><a href="Introduction.html" target="Modules">Introduction to System Report</a> </li> <li><a href="cpuinfo.html" target="Modules">CPU Information</a> </li> <li><a href="drive.html" target="Modules">Drive Information</a> </li> <li><a href="environment.html" target="Modules">Environment Variables</a> </li> <li><a href="software.html" target="Modules">Installed Packages</a> </li> <li><a href="logfiles.html" target="Modules">Log Files</a> </li> <li><a href="memory.html" target="Modules">Memory</a> </li> <li><a href="modules.html" target="Modules">Modules Loaded</a> </li> <li><a href="network.html" target="Modules">Network</a> </li> <li><a href="opsys.html" target="Modules">Operating Systems</a> </li> <li><a href="PCIBus.html" target="Modules">PCI Bus</a> </li> <li><a href="usb.html" target="Modules">USB Devices</a> </li></ul>EOF## Here we create cpuinfo.htmlecho "Creating cpuinfo.html"cat > ~/SysReport/cpuinfo.html << EOF<html><head><meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type"><title>CPU Information</title></head><body><p>The command that generates the following out put is:<p>cat /proc/cpuinfo >> ~/SysReport/cpuinfo.html <table style="text-align: left; width: 100%;" border="2" cellpadding="2"cellspacing="2"><tbody><tr><td style="vertical-align: top; background-color: rgb(153, 153, 255);">cat /proc/cpuinfo</td></tr><tr><td style="vertical-align: top; background-color: rgb(153, 255, 255);"><pre>EOF# generate the out put from system filecat /proc/cpuinfo >> ~/SysReport/cpuinfo.html# add the end of the filecat >> ~/SysReport/cpuinfo.html << EOF</pre></td></tr></tbody></table><br>To get the out put of this command in terminal use the following form:<br><br>cat /proc/cpuinfo<p>This will output the information to the terminal screen. You can't open the file cpuinfo in Gedit but the cat command gives you access to the contents of it. It is actually a place in memory, not an actual file on your hard drive and that is why you cannot open it in a text editor.</body></html>EOF## Here we create drive.htmlecho "Creating drive.html"cat > ~/SysReport/drive.html << EOF<html><head><meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type"><title>Drive Information</title></head><body><br>The command that generates the following out put is:<br>cat /proc/diskstats >> ~/SysReport/drive.html <table style="text-align: left; width: 100%;" border="2" cellpadding="2"cellspacing="2"><tbody><tr><td style="vertical-align: top; background-color: rgb(153, 153, 255);">cat /proc/diskstats</td></tr><tr><td style="vertical-align: top; background-color: rgb(153, 255, 255);"><pre>EOF# generate the out put from system filecat /proc/diskstats >> ~/SysReport/drive.html# add the end of the filecat >> ~/SysReport/drive.html << EOF</pre></td></tr></tbody></table><br>To get the out put of this command in terminal use the following form:<br><br>cat /proc/diskstats<p>This will output the information to the terminal screen. I'm not sure who this information might be useful to, it's greek to me.<p>The following output is generated with this command:<p>df -h >> ~/SysReport/drive.html<p> The -h switch makes it generate human readable output grouped in G, M, and K bytes 8-) You can get the out put in bytes only by using the -b switch instead of -h<table style="text-align: left; width: 100%;" border="2" cellpadding="2"cellspacing="2"><tbody><tr><td style="vertical-align: top; background-color: rgb(153, 153, 255);">df -h</td></tr><tr><td style="vertical-align: top; background-color: rgb(153, 255, 255);"><pre>EOF# generate the out put from system filedf -h >> ~/SysReport/drive.html# try to prompt user to hit entercat >> ~/SysReport/drive.html << EOF</pre></td></tr></tbody></table><p>There is another command you can use to get your partition information but this script cannot run it as it doesn't have super user permission. To have your partition information included in this document, run the following command in terminal, then re-run SystemReport.sh to have that information added in here.<p>sudo fdisk -l > ~/SysReport/fdisk.txt<p>You will be prompted for your password, type it in and hit enter. You won't see any characters echoed by terminal when you type your password, but just keep typing, it's getting them.<p>This will create a text file of the fdisk command output which when you re-run SystemReport.sh will be detected and added into this file. Don't forget to update fdisk.txt if you change your partitions around.EOF# If the user has ran the ""sudo fdisk -l > ~/SysReport/fdisk.txt" command, add the content# of fdisk.txt into drive.htmlif [ -e ~/SysReport/fdisk.txt ] then cat >> ~/SysReport/drive.html << EOF<P> I see you've created fdisk.txt so here is the information from it below.<table style="text-align: left; width: 100%;" border="2" cellpadding="2"cellspacing="2"><tbody><tr><td style="vertical-align: top; background-color: rgb(153, 153, 255);">sudo fdisk - l</td></tr><tr><td style="vertical-align: top; background-color: rgb(153, 255, 255);"><pre>EOF cat ~/SysReport/fdisk.txt >> ~/SysReport/drive.html cat >> ~/SysReport/drive.html << EOF</pre></td></tr></tbody></table><p>Of course you can get your partition information at any time by opening a terminal window and running the following command. You will be prompted for your password, then the output will go to the terminal window.<p>sudo fdisk -l</body></html>EOFfi# Create the PCIBus.html file with the lspci command# first write the top of the file to diskecho "Creating PCIBus.html"cat > ~/SysReport/PCIBus.html << EOF<html><head><meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type"><title>PCI Bus Information</title></head><body><p> This file has information about your PCI bus and the things connected to it. It gives you a good list of the hardware in your computer.<p>This first command that generates the following out put is:<p>lspci -t -vv >> ~/SysReport/PCIBus.html<p> The -t makes the output in tree form and -vv means very verbose<table style="text-align: left; width: 100%;" border="2" cellpadding="2"cellspacing="2"><tbody><tr><td style="vertical-align: top; background-color: rgb(153, 153, 255);">lspci -t -vv</td></tr><tr><td style="vertical-align: top; background-color: rgb(153, 255, 255);"><pre>EOF# generate the out put into the PCIBus.html filelspci -t -vv >> ~/SysReport/PCIBus.html# Now add the next section of the filecat >> ~/SysReport/PCIBus.html << EOF</pre></td></tr></tbody></table><p>This next section uses a different set of switches to generate a bit more detailed output.<p>The command to generate this section of the file is:<p>lspci -b -v >> ~/SysReport/PCIBus.html<p>The -b means bus centric and -v is just verbose<p>For a reference to the lspci command and it's other switches see <a href="http://linux.die.net/man/8/lspci" target="blank">lspci(8) - Linux man page</a></p><table style="text-align: left; width: 100%;" border="2" cellpadding="2"cellspacing="2"><tbody><tr><td style="vertical-align: top; background-color: rgb(153, 153, 255);">lspci -b -v</td></tr><tr><td style="vertical-align: top; background-color: rgb(153, 255, 255);"><pre>EOF# out put the next command to disklspci -b -v >> ~/SysReport/PCIBus.html# now write then end of the filecat >> ~/SysReport/drive.html << EOF</pre></td></tr></tbody></table></body></html>EOF# generate a memory report file# first write the top of the file to diskecho "Creating memory.html"cat > ~/SysReport/memory.html << EOF<html><head><meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type"><title>Memory Information</title></head><body><p> This file has some information about your memory.<p>This first command that generates the following out put is:<p>free -m >> ~/SysReport/memory.html<p> The -m makes the output in Megabytes. -b will give the results in bytes and running just free with no switches defaults to output in Kilobytes.<table style="text-align: left; width: 100%;" border="2" cellpadding="2"cellspacing="2"><tbody><tr><td style="vertical-align: top; background-color: rgb(153, 153, 255);">free -m</td></tr><tr><td style="vertical-align: top; background-color: rgb(153, 255, 255);"><pre>EOF# out put the next command to diskfree -m >> ~/SysReport/memory.html# now write the next part of the filecat >> ~/SysReport/memory.html << EOF</pre></td></tr></tbody></table><p>Swappiness is a measure of how aggressively Ubuntu swaps memory out to the swap file or partition. This next command checks the value of swappiness.<p>cat /proc/sys/vm/swappiness<p>Swappiness can be set from 0 to 100 with 100 being the most aggressively paged out. A low number like 10 is recommended for desktops, while 60 is the default in Ubuntu. 60 is also recommended for servers.<table style="text-align: left; width: 100%;" border="2" cellpadding="2"cellspacing="2"><tbody><tr><td style="vertical-align: top; background-color: rgb(153, 153, 255);">cat /proc/sys/vm/swappiness</td></tr><tr><td style="vertical-align: top; background-color: rgb(153, 255, 255);"><pre>EOF# # out put the next command to diskcat /proc/sys/vm/swappiness >> ~/SysReport/memory.html# now write the end of the filecat >> ~/SysReport/memory.html << EOF</pre></td></tr></tbody></table><p>Here is the <A HREF="https://help.ubuntu.com/community/SwapFaq" Target="blank">Ubuntu Swap Partition FAQ</a> so you can get up to speed on swap files. Among other things it talks about, the article tells how to adjust swappiness.</body></html>EOF# generate a network report file# first write the top of the file to diskecho "Creating network.html"cat > ~/SysReport/network.html << EOF<html><head><meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type"><title>Network Information</title></head><body><p> This file has some information about your network.<p>This first command that generates the following out put is:<p>ifconfig -a >> ~/SysReport/network.html<p> The -a makes ifconfig output all network connections.<table style="text-align: left; width: 100%;" border="2" cellpadding="2"cellspacing="2"><tbody><tr><td style="vertical-align: top; background-color: rgb(153, 153, 255);">ifconfig -a</td></tr><tr><td style="vertical-align: top; background-color: rgb(153, 255, 255);"><pre>EOF# out put the next command to diskifconfig -a >> ~/SysReport/network.html# now write then end of the filecat >> ~/SysReport/network.html << EOF</pre></td></tr></tbody></table><p>This next command checks to see if you are connected to a network currently.<p>cat /sys/class/net/eth0/carrier<p>This location returns a 0 if you are not connected, and a 1 if you are connected to a network.<table style="text-align: left; width: 100%;" border="2" cellpadding="2"cellspacing="2"><tbody><tr><td style="vertical-align: top; background-color: rgb(153, 153, 255);">cat /sys/class/net/eth0/carrier</td></tr><tr><td style="vertical-align: top; background-color: rgb(153, 255, 255);"><pre>EOF# # out put the next command to diskcat /sys/class/net/eth0/carrier >> ~/SysReport/network.html# now write the end of the filecat >> ~/SysReport/network.html << EOF</pre></td></tr></tbody></table></body></html>EOF## create the opsys.html file# write the head of the fileecho "Creating opsys.html"cat > ~/SysReport/opsys.html << EOF<html><head><meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type"><title>Operating System Information</title></head><body><p>This first command checks a place on your file system which is a location in memory to get the version of Ubuntu you are using. The command is in the top of the following table.<table style="text-align: left; width: 100%;" border="2" cellpadding="2"cellspacing="2"><tbody><tr><td style="vertical-align: top; background-color: rgb(153, 153, 255);">cat /etc/issue</td></tr><tr><td style="vertical-align: top; background-color: rgb(153, 255, 255);"><pre>EOFcat /etc/issue >> ~/SysReport/opsys.htmlcat >> ~/SysReport/opsys.html << EOF</pre></td></tr></tbody></table><p>This command generates the contents of your Grub menu.lst file if you are on a dual booting system.<p>cat /boot/grub/menu.lst >> ~/SysReport/opsys.html<p>If there is no menu.lst file on your computer the following output will say so.<p>The file menu.lst can be edited with Gedit if you start it with gksu in terminal with the following command.<p>gksu gedit<p>You will be prompted for your password after you hit enter.<p> It is much easier to make changes to the grub menu with a grub menu editor than editing it with Gedit. To do so open Synaptic Package Manager and install the package qgrubeditor or kgrubeditor, I prefer the qgrubeditor myself.<table style="text-align: left; width: 100%;" border="2" cellpadding="2"cellspacing="2"><tbody><tr><td style="vertical-align: top; background-color: rgb(153, 153, 255);">cat /boot/grub/menu.lst</td></tr><tr><td style="vertical-align: top; background-color: rgb(153, 255, 255);"><pre>EOF# test for existence of menu.lst file and do output accordinglyif [ -e /boot/grub/menu.lst ] then cat /boot/grub/menu.lst >> ~/SysReport/opsys.html else echo "No menu.lst file found" >> ~/SysReport/opsys.htmlfi# now write the next part of the filecat >> ~/SysReport/opsys.html << EOF</pre></td></tr></tbody></table><p>If the menu.lst file exists, we can check to see wbere grub is installed with the following command.<p>cat /boot/grub/device.map >> ~/SysReport/opsysy.html<table style="text-align: left; width: 100%;" border="2" cellpadding="2"cellspacing="2"><tbody><tr><td style="vertical-align: top; background-color: rgb(153, 153, 255);">cat /boot/grub/device.map</td></tr><tr><td style="vertical-align: top; background-color: rgb(153, 255, 255);"><pre>EOF# get the device.map infoif [ -e /boot/grub/menu.lst ] then cat /boot/grub/device.map >> ~/SysReport/opsys.html else echo "no menu.lst file found" >> ~/SysReport/opsys.htmlfi# write the end of the filecat >> ~/SysReport/opsys.html << EOF</pre></td></tr></tbody></table><p>To learn more about grub go to the <a href="http://users.bigpond.net.au/hermanzone/p15.htm" target="blank">grub page</a><p>Now we check the version of your Linux kernel.<table style="text-align: left; width: 100%;" border="2" cellpadding="2"cellspacing="2"><tbody><tr><td style="vertical-align: top; background-color: rgb(153, 153, 255);">uname -a</td></tr><tr><td style="vertical-align: top; background-color: rgb(153, 255, 255);"><pre>EOFuname -a >> ~/SysReport/opsys.htmlcat >> ~/SysReport/opsys.html << EOF</pre></td></tr></tbody></table><p>This next command generates a bit more information about your version of Ubuntu.<table style="text-align: left; width: 100%;" border="2" cellpadding="2"cellspacing="2"><tbody><tr><td style="vertical-align: top; background-color: rgb(153, 153, 255);">lsb_release -a</td></tr><tr><td style="vertical-align: top; background-color: rgb(153, 255, 255);"><pre>EOFlsb_release -a 2> /dev/null >> ~/SysReport/opsys.htmlcat >> ~/SysReport/opsys.html << EOF</pre></td></tr></tbody></table></body></html>EOF# create logfiles.html# module added 9/22/08 by C Ray Parrishecho "Creating logfiles.html"cat > ~/SysReport/logfiles.html << EOF<html><head><meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type"><title>Log Files</title></head><body><p>This file is the syslog.conf file which determines what messages from the system get sent to which log file. You can look up what log files are available for inspection in this file.<p>The command that generates the following out put is:<p>cat /etc/syslog.conf >> ~/SysReport/logfiles.html<table style="text-align: left; width: 100%;" border="2" cellpadding="2"cellspacing="2"><tbody><tr><td style="vertical-align: top; background-color: rgb(153, 153, 255);">cat /etc/syslog.conf</td></tr><tr><td style="vertical-align: top; background-color: rgb(153, 255, 255);"><pre>EOF# out put the next command to diskcat /etc/syslog.conf >> ~/SysReport/logfiles.html# now write the next part of the filecat >> ~/SysReport/logfiles.html << EOF</pre></td></tr></tbody></table><p>The syslog.conf file can be edited with a text editor but may need to be started with gksu priveleges to write to file any changes you make. Use the following command -<p>gksu gedit /etc/syslog.conf<p>You will be prompted for your password when you run the above command.</body></html>EOF# create software.html# module added 9/22/08 by C Ray Parrishecho "Creating software.html"cat > ~/SysReport/software.html << EOF<html><head><meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type"><title>Log Files</title></head><body><p>The following is a list of all packages installed on this system. It is in reality a list of all of the subfolders in your /usr/share/doc folder. Each subfolder there corresponds to a package with the same name which is installed on your system.<p>For this out put we have to be in the right folder first so we cd<p>cd /usr/share/doc<p>Then we run the ls command to get a list of the folders<p>ls -a --group-directories-first >> ~/SysReport/software.html<p><a href=#versions>Jump down to Software Version Information</a><table style="text-align: left; width: 100%;" border="2" cellpadding="2"cellspacing="2"><tbody><tr><td style="vertical-align: top; background-color: rgb(153, 153, 255);">cd /usr/share/doc<br>ls -a --group-directories-first</td></tr><tr><td style="vertical-align: top; background-color: rgb(153, 255, 255);"><pre>EOFecho " inventory of /usr/share/doc"# out put the next command to disk# first change to the right foldercd /usr/share/doc# and put a list of it's folders into software.htmlls -a --group-directories-first >> ~/SysReport/software.html# now write the next part of the filecat >> ~/SysReport/software.html << EOF</pre></td></tr></tbody></table><a name="versions"<p><a href="#updates">Jump to updateable packages</a><p>There is another command which you can install on your system which will give you the current version of all installed software along with whether or not it is up to date. To install this package issue the following command in terminal -<p> sudo apt-get install apt-show-versions<p>You will be prompted for your password and then the package will be installed.<p>Now re-run the SystemReport.sh script to add the software version information into this document below.<table style="text-align: left; width: 100%;" border="2" cellpadding="2"cellspacing="2"><tbody><tr><td style="vertical-align: top; background-color: rgb(153, 153, 255);">apt-show-versions</td></tr><tr><td style="vertical-align: top; background-color: rgb(153, 255, 255);"><pre>EOFecho " generating version list"if [ -e /usr/bin/apt-show-versions ] then touch ~/SysReport/versions.txt chmod 777 ~/SysReport/versions.txt apt-show-versions > ~/SysReport/versions.txt echo " Sorting version list" sort ~/SysReport/versions.txt >> ~/SysReport/software.html else echo "apt-show-versions not found, follow directions above to get this output" >> ~/SysReport/software.htmlficat >> ~/SysReport/software.html << EOF</pre></td></tr></tbody></table><A NAME="updates"><p>In this next output section we are looking to see which packages on our system need updating.<p>To do this we add a -u switch to the command from the last section as you can see at the top of the table below.<p>If there is no out put in the following section, all software on your system is up to date.<table style="text-align: left; width: 100%;" border="2" cellpadding="2"cellspacing="2"><tbody><tr><td style="vertical-align: top; background-color: rgb(153, 153, 255);">apt-show-versions -u</td></tr><tr><td style="vertical-align: top; background-color: rgb(153, 255, 255);"><pre>EOF# now we add the output of packages which need updating if anyecho " generating list of updates"# first be sure they have the command installedif [ -e /usr/bin/apt-show-versions ] # check to see if output of command is empty then texttest=$(apt-show-versions -u 2> /dev/null) if [ "$texttest" == "" ] # if it's empty, all software is up to date then echo "Your software is all up to date." >> ~/SysReport/software.html # otherwise add list of packages which need updating else apt-show-versions -u 2> /dev/null >> ~/SysReport/software.html fi # if they don't have the command installed tell them else echo "you must install apt-show-versions to get this output" >> ~/SysReport/software.htmlficat >> ~/SysReport/software.html << EOF</pre></td></tr></tbody></table><p>This next section isn't the result of a command, it is merely a link to a file on your system which keeps a lot of information about installed software in it. It includes the version, what packages it depends on to operate, which packages they conflict with, and a description of the packages function.<p>Note that even if you are viewing the sample System Report online the following link is to a file on your system and is not part of the sample report.<p>You can open the following file with your text editor.<p>The reason I don't cat this file into the web page report is that on my system it is 1.4 megabytes large so it isn't practical to import it.<table style="text-align: left; width: 100%;" border="2" cellpadding="2"cellspacing="2"><tbody><tr><td style="vertical-align: top; background-color: rgb(153, 153, 255);">/var/lib/dpkg/status</td></tr><tr><td style="vertical-align: top; background-color: rgb(153, 255, 255);"><a href="file:///var/lib/dpkg/status">Software Information File</a></td></tr></tbody></table></body></html>EOF# create environment.html# module added 9/22/08 by C Ray Parrishecho "Creating environment.html"cat > ~/SysReport/environment.html << EOF<html><head><meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type"><title>Environment Variables</title></head><body><p>This page is all about your environment variables. They are used by programs to look up global settings for your system. One of these settings is the PATH variable which stores the paths where the system looks for a command when you type in just it's name in terminal.<p>The following command prints out all environment variables<p>printenv<p>to get only one variables value there are two ways as follows, both work<p> printenv PATH<p>You can also use "echo \$variablename" to return the value of any variable.<table style="text-align: left; width: 100%;" border="2" cellpadding="2"cellspacing="2"><tbody><tr><td style="vertical-align: top; background-color: rgb(153, 153, 255);">printenv</td></tr><tr><td style="vertical-align: top; background-color: rgb(153, 255, 255);"><pre>EOF# out put the next command to diskprintenv >> ~/SysReport/environment.html# now write the next part of the filecat >> ~/SysReport/environment.html << EOF</pre></td></tr></tbody></table><p>To learn more about environment variables and how to set them have a look at <a href="https://help.ubuntu.com/community/EnvironmentVariables" target="blank">Environment Variables - Ubuntu Community documentation</a></body></html>EOF# create modules.html# module added 9/29/08 by C Ray Parrishecho "Creating modules.html"cat > ~/SysReport/modules.html << EOF<html><head><meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type"><title>Environment Variables</title></head><body><p>This page lists the modules you have loaded in memory and how large they are. To generate this out put I have used the lsmod command which pretties up the information also available at /proc/modules via the cat command.<table style="text-align: left; width: 100%;" border="2" cellpadding="2"cellspacing="2"><tbody><tr><td style="vertical-align: top; background-color: rgb(153, 153, 255);">lsmod</td></tr><tr><td style="vertical-align: top; background-color: rgb(153, 255, 255);"><pre>EOF# out put the next command to disklsmod >> ~/SysReport/modules.html# now write the next part of the filecat >> ~/SysReport/modules.html << EOF</pre></td></tr></tbody></table></body></html>EOF# create usb.html# module added 9/29/08 by C Ray Parrishecho "Creating usb.html"cat > ~/SysReport/usb.html << EOF<html><head><meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type"><title>USB Devices</title></head><body><p>This page lists the USB devices attached to your system. The -v switch on the following command means verbose out put.<table style="text-align: left; width: 100%;" border="2" cellpadding="2"cellspacing="2"><tbody><tr><td style="vertical-align: top; background-color: rgb(153, 153, 255);">lsusb -v</td></tr><tr><td style="vertical-align: top; background-color: rgb(153, 255, 255);"><pre>EOF# out put the next command to disklsusb -v 2>/dev/null >> ~/SysReport/usb.html# now write the next part of the filecat >> ~/SysReport/usb.html << EOF</pre></td></tr></tbody></table></body></html>EOFecho "Loading System Report in browser"# call the web browser with the System Report loaded# get the command for the users default browserBROWSER=`gconftool-2 --get '/desktop/gnome/url-handlers/http/command' | cut -f1 -d' ' `# call that browser with the report url${BROWSER} ~/SysReport/index.html &exit

I hope someone knows what is happening with this, perhaps some kind Ubuntu user could try to run the file themselves and see if it works on their system. To run it I had to set the permissions to allow it to execute as a program, and I had her do that on her copy first as well.

If you don't want to copy and paste and save file you can download a copy of the file at my web site. Here's the page it's on.

System Report Script for Ubuntu



Please help me as I don't have a clue as to why it won't run for her.

Thanks for anyhelp you can be.

Later, Ray Parrish

Edited by Ray Parrish, 03 November 2008 - 11:51 PM.


BC AdBot (Login to Remove)

 


#2 raw

raw

    Bleeping Hacker


  • Members
  • 2,577 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Texas
  • Local time:07:37 AM

Posted 03 November 2008 - 10:00 PM

cd ~/Desktop
SystemReport.sh


cd ~/Desktop
chmod 755 SystemReport.sh
sh SystemReport.sh or
./SystemReport.sh

rawsig.png

 rawcreations.net          @raw_creations


Current systems: WHAT OS, BackTrack-raw, PCLinuxOS, Peppermint OS 6, Kali Linux

and a custom Linux From Scratch server hosting a bunch of top secret stuff.


#3 Ray Parrish

Ray Parrish
  • Topic Starter

  • Members
  • 91 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Cottage Grove, Oregon
  • Local time:04:37 AM

Posted 03 November 2008 - 10:32 PM

cd ~/Desktop
SystemReport.sh


cd ~/Desktop
chmod 755 SystemReport.sh
sh SystemReport.sh or
./SystemReport.sh


Thanks for the reply. I never thought of chmod, mostly because I can't ever remember the numbers to use with it.

Still, I have had to do none of that to run the file on my system. I used the File Browser property dialog for the file to check mark the "Allow executing as program" setting and have been running the script from Terminal just by typing in ~/Desktop/SystemReport.sh by itself with no problems.

It still has me baffled that the same procedure wouldn't work on my friends machine.

If your advice works I'll have to modify the instructions on my web page. 8-)

Thanks again, and I'll get back with you the next time I can get my friend to try running it again.

Later, Ray Parrish

#4 Ray Parrish

Ray Parrish
  • Topic Starter

  • Members
  • 91 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Cottage Grove, Oregon
  • Local time:04:37 AM

Posted 04 November 2008 - 05:36 PM

Hello again,

Well, those commands didn't work either. I don't know what's going on with her machine and she didn't tell me the error messages she got either so I'm waiting for an email back from her with that information.

In the meantime... Did you try to run my script on your system, and if so, did it work for you? If not, would you please do so and let me know if you encounter any errors? This is driving me buggy as it works perfectly for me, you can see the output from the script when it's ran on my machine on my web site at this location -

http://www.rayslinks.com/scripts/Sample/index.html

And here is the download link for the script -

http://www.rayslinks.com/scripts/SystemReport.sh

Thanks again, Ray Parrish

#5 raw

raw

    Bleeping Hacker


  • Members
  • 2,577 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Texas
  • Local time:07:37 AM

Posted 04 November 2008 - 07:04 PM

Creating SysReport Folder
SystemReport.sh: line 686: syntax error near unexpected token `else'
SystemReport.sh: line 686: ` else echo "you must install apt-show-versions to'get this output" >> ~/SysReport/software.html


I do not have this progam.

rawsig.png

 rawcreations.net          @raw_creations


Current systems: WHAT OS, BackTrack-raw, PCLinuxOS, Peppermint OS 6, Kali Linux

and a custom Linux From Scratch server hosting a bunch of top secret stuff.


#6 Ray Parrish

Ray Parrish
  • Topic Starter

  • Members
  • 91 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Cottage Grove, Oregon
  • Local time:04:37 AM

Posted 04 November 2008 - 09:05 PM

Creating SysReport Folder
SystemReport.sh: line 686: syntax error near unexpected token `else'
SystemReport.sh: line 686: ` else echo "you must install apt-show-versions to'get this output" >> ~/SysReport/software.html


I do not have this program.


Hello again,

Thanks for trying the script. At least it tried to run on your system, my friend can't even get it to do that. Also, thank you for posting those error messages.

I forgot to put semicolons on the end of the instructions ,list in the Then part of my If statement. It's never tossed an error for me, maybe because I have apt-show-versions installed. Thanks for catching that for me.

I've uploaded a new copy with the if statement fixed, perhaps you could download it and give it a try again?

Thanks, Ray Parrish

Edited by Ray Parrish, 04 November 2008 - 09:06 PM.


#7 raw

raw

    Bleeping Hacker


  • Members
  • 2,577 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Texas
  • Local time:07:37 AM

Posted 04 November 2008 - 11:37 PM

My my...you've been naughty haven't you?
The script does work, very nice.
From opsys.html:

[The system is up and running now.

Login as "root" with password "toor"

Now everyone has my root password. :thumbsup:
Your mission, should you accept it, is to tell me
why it didn't work for me or your friend.
Here is your hint: There is no syntax error on line 686.
It runs on your machine. It runs on my machine (now).
I did not change any of your code. I'll give you some
time to research and solve.

If you figure it out...feel free to bang your head on a wall.
If not, I will tell you, then...feel free to bang your head on a wall.

rawsig.png

 rawcreations.net          @raw_creations


Current systems: WHAT OS, BackTrack-raw, PCLinuxOS, Peppermint OS 6, Kali Linux

and a custom Linux From Scratch server hosting a bunch of top secret stuff.


#8 Ray Parrish

Ray Parrish
  • Topic Starter

  • Members
  • 91 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Cottage Grove, Oregon
  • Local time:04:37 AM

Posted 05 November 2008 - 01:05 AM

Here is your hint: There is no syntax error on line 686.
It runs on your machine. It runs on my machine (now).
I did not change any of your code. I'll give you some
time to research and solve.

If you figure it out...feel free to bang your head on a wall.
If not, I will tell you, then...feel free to bang your head on a wall.


OK, I've done all the research on this that I can... so, what am I missing? From the tone of your post it must be something totally simple that I missed.

Later, Ray Parrish

#9 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:06:37 AM

Posted 05 November 2008 - 12:27 PM

Let's see if I can guess, the script was created by a user on one machine, and it is being run by a user on another machine.......

#10 Ray Parrish

Ray Parrish
  • Topic Starter

  • Members
  • 91 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Cottage Grove, Oregon
  • Local time:04:37 AM

Posted 05 November 2008 - 01:49 PM

Let's see if I can guess, the script was created by a user on one machine, and it is being run by a user on another machine.......


Yes, that is correct. Is that a problem?

It must be because I can't get it to work, so give me a break and tell me why since I'm a really new user to Ubuntu.

I've googled "make bash script portable" but I'm not getting the info I need.

Well, I've been trying, and I can't seem to formulate a search term that brings any results related to this problem.

Thanks, Ray Parrish

Edited by Ray Parrish, 05 November 2008 - 02:09 PM.


#11 Ray Parrish

Ray Parrish
  • Topic Starter

  • Members
  • 91 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Cottage Grove, Oregon
  • Local time:04:37 AM

Posted 05 November 2008 - 03:29 PM

Hello again,

Well, my friend has been able to get the script to attempt to run on her system now. She's still got the old copy with the syntax error, so I told her to get the new one and give it a try.

Evidently she deleted the !#/bin/bash line at the top of the script and it worked for her. It appears her bash resides somewhere else which is very weird, I thought it was in the same place on all Ubuntu installations.

I did find a web page that recommends making that first line with #!/usr/bin/env bash to find bash on other systems, so I'll give that a try and see if it works.

Later, Ray Parrish

#12 raw

raw

    Bleeping Hacker


  • Members
  • 2,577 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Texas
  • Local time:07:37 AM

Posted 05 November 2008 - 09:30 PM

I did not change any of your code.

Groovicus gave you the best answer.(but it's not because of the "user")
Somewhere between you creating the script and the script
residing on the web server either you:
Opened the file with notepad and saved it. Notepad does bad things
to UNIX files, like adding End of Line CR/LF markers. This hoses the script.
Or your FTP client transferred the file to your server in "binary mode"
instead of "ascii mode". This too hoses the script.

Have the friend open the script with Kwrite.
Click - Tools - End of Line - UNIX
Click "Save"
Now it should run...did for me. :thumbsup:

I did find a web page that recommends making that first line with #!/usr/bin/env bash

bash lives in /bin on every Linux system I have used. In some weird world where bash is not in /bin it
will usually be linked to by /bin/sh. The exception being a system where "bash" is not the default
interpreter and /bin/sh may link to Korn shell(ksh), C shell(csh) or some other shell.

Hope this has been helpful.

rawsig.png

 rawcreations.net          @raw_creations


Current systems: WHAT OS, BackTrack-raw, PCLinuxOS, Peppermint OS 6, Kali Linux

and a custom Linux From Scratch server hosting a bunch of top secret stuff.


#13 Ray Parrish

Ray Parrish
  • Topic Starter

  • Members
  • 91 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Cottage Grove, Oregon
  • Local time:04:37 AM

Posted 06 November 2008 - 12:36 AM

Groovicus gave you the best answer.(but it's not because of the "user")
Somewhere between you creating the script and the script
residing on the web server either you:
Opened the file with notepad and saved it. Notepad does bad things
to UNIX files, like adding End of Line CR/LF markers. This hoses the script.
Or your FTP client transferred the file to your server in "binary mode"
instead of "ascii mode". This too hoses the script.

Have the friend open the script with Kwrite.
Click - Tools - End of Line - UNIX
Click "Save"
Now it should run...did for me. :thumbsup:


Well I haven't been in Windows in weeks so I haven't opened the script in Notepad, and I just set FileZilla to upload in Ascii mode as it was set to Auto so I'm not sure which mode it was using.

Thanks for the tips raw, now I just need to fix the error with the if statement that is still tossing an error on her machine. It complains of an unexpected else, and my latest try to fix that is to add semi-colons to the end of all of the statements within the then portion of the if. I haven't found a good example of the use of if in bash, all the docs just show the skeleton syntax and none of them show semi-colons so I'm just guessing on that one.

It's hard to debug something that doesn't occur on my machine, every version of the script has ran on my machine without errors, go figure.

Thanks again, later, Ray Parrish

EDIT: Wait a minute! I just remembered that when I first started the script that I imported the code of an html file that I had created in Windows to create the frameset code in the script... I bet that's what the problem is. Only thing I don't figure is why all this time it has ran just fine for me?

Edited by Ray Parrish, 06 November 2008 - 12:46 AM.


#14 Ray Parrish

Ray Parrish
  • Topic Starter

  • Members
  • 91 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Cottage Grove, Oregon
  • Local time:04:37 AM

Posted 06 November 2008 - 07:19 PM

Hello,

This is an update on this problem. My friend installed Kwrite and followed the instructions for setting the line ends to Unix style, and now the script works for her! Yay!

Now for the puzzle, I also installed Kwrite and fixed the line endings before uploading to the server.

Well, we figured out what was wrong... FileZilla was hosing the file on upload! I put the file in a tar.gz archive and uploaded it, and when she got it on the other end it still worked!

So it wasn't my syntax after all. :thumbsup:

Later and thanks for all the help! Ray Parrish

#15 raw

raw

    Bleeping Hacker


  • Members
  • 2,577 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Texas
  • Local time:07:37 AM

Posted 06 November 2008 - 09:27 PM

So it wasn't my syntax after all.

I posted that there nothing wrong with the code.
Even when you can't see that errant CR/LF know that
bash will find it.
Extra info: Since it's only one file you don't need to tar it.
zip SystemReport.zip SystemReport.sh
In the unlikely event you need to use Windows to edit a bash
script I use and recommend MetaPad.
http://liquidninja.com/metapad/

rawsig.png

 rawcreations.net          @raw_creations


Current systems: WHAT OS, BackTrack-raw, PCLinuxOS, Peppermint OS 6, Kali Linux

and a custom Linux From Scratch server hosting a bunch of top secret stuff.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users