LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 03-01-2009, 03:58 PM   #1
okos
Member
 
Registered: May 2007
Location: California
Distribution: Slackware/Ubuntu
Posts: 609

Rep: Reputation: 38
Cool My first bash script. Yea!!


Hi all,

Why I wrote this script. I wrote this script because I have broken my system several times trying new things. I had gotten tired of customizing my system by hand on every new install. Furthermore, I also can use this script to customize other computers at home which have no network access.

Other then basic bash commands, I learned much of the scripting from rute. See my signature below for the link.

I still consider myself a novice after a two year process of converting from windows to Linux Slackware. So if you wish to give input, please provide info so that even noobs can learn from it.

I invite your feedback on how to improve on the first script I had just finished. I tested parts of the script when developing it in a directory I named "test". However, since I have not been able to install vmware on my current system nor have I broken my system in a while, I have not been able to fully test the new script.

Some background info. I have a 1TB usb drive in which I use as a personal repository for my custom files and slack packages. So, this script will not work on any other computer systems other then my home computers. However, I have no problem with others taking ideas from my script. "Freely I receive, freely do I give."

I have a couple questions that I hope some of you can answer.

1. I used the sed command to edit a file for personal use. It seems that sed will not actually edit a file. From what I understand, sed streams the file in question and replaces the desired changes into a different file. I then have to move the new file to replace the original file. This seems a little awkward. There should be a better way to go about editing a file.

2. I know there are a bunch of ways for non root users to turn off the computer. I happened to try one method by adding a group called "shutdown". Adding it to the /etc/sudoers. Changing ownership of /sbin/halt and /sbin/reboot from root:root to root:shutdown. Adding the shutdown group to specific users. Adding the alias "off"
to .bashrc. Having changed ownership of the /sbin files, I have no problem turning off the computer at runlevel 3 as a user. I am wondering if changing ownership might cause a problem shutting down in runlevel 4?

3. One part of the script that I have yet to figure out is to search and add printers from from from the network. Currently, I have a printer connected to my wife's xp. Her computer name is mom and the shared printer is an HP L7580. Now before someone tries to tell me how to connect to this printer, that is not the problem. I already included that into the script. My question is, perhaps the printer is moved to another computer. Or a second printer has been added to the network as a shared printer. Then the current settings will not work. I want to write a script where all of the computer names are searched out first of all. Then printers are searched. Then all available network printers are added to cups. My question is there a command to search out available printers on a network? Ive googled it but have not found a solution.

Code:
 #!/bin/sh
#Because I break my system so many time. I decided to write my firt script to quickly customize things once
#Slackware is installed.
#One assumption I made is that all of my backup files are in their current locations on my usb drive.
#most of the files are located in /backup/Dennis/linux/ directory
#I gave simple explinations so I dont forget what each part is for.


#User input function to see if users agree to each step.
function question ()
 {
N=1
 while test "$N" -le "3"
 do
echo "Do you want to $TITLE ? y/n"; read X

case $X in
	y|Y|Yes|YES)
		OUTCOME="y"
		break
	;;
	
	n|N|No|NO)
		OUTCOME="n"
		break
	;;
	
	*)
		echo "You did not select y or n"
		OUTCOME="n"
	;;
esac
	
         echo "You have 3 tries you are on number $N"
if test "$N" = "3" ; then
	echo "You did not select yes so your answer will be considered NO!"
fi
	N=$[N+1]
	
         
 done
	
}

#checking who is executing this script
WHO=`whoami`
if test $WHO != "root"; then
echo "You need to be in root to execute this script!"
exit
fi

#Confirming mounting usb drive. 
echo "***Mounting backup files ***"
if test -e /backup = "" ;  then
	mkdir /backup
	MYDISK=`fdisk -l | grep 11918  | grep -o '/dev/sd..'`
fi

# unmount the default mount of /media/disk or /media/disk-1
umount "$MYDISK" 
mount "$MYDISK" /backup
#test to see if disk exists. 
if test "$MYDISK" = "" ; then
	echo "***You need the usb WD drive to run this script***"
	exit
fi

 
echo "***Install essential dellfand first***"
#prevents overheating of cpu
cp /backup/Dennis/linux/tar/* /usr/local/src
tar jxf /usr/local/src/dellfand-0.9.tar.bz2
cd /usr/local/src/dellfand-0.9 ; make
./dellfand 1 10 38 39 45
chmod +x dellfand ; cp dellfand /usr/local/bin/
echo "dellfand 1 10 38 39 45"


echo "***Installing Custom Startup Scripts and custom files***" 
cp /etc/rc.d/rc.local /etc/rc.d/rc.local.BAK
cp /etc/rc.d/rc.inet1.conf /etc/rc.d/rc.inet1.conf.BAK
cp /etc/rc.d/rc.wireless.conf /etc/rc.d/rc.wireless.conf.BAK
cp /etc/wpa_supplicant.conf /etc/wpa_supplicant.conf.BAK
cp /etc/modprobe.d/blacklist /etc/modprobe.d/blacklist.BAK
cp /etc/samba/smb.conf /etc/samba/smb.conf.BAK
cp /etc/cup/printers.conf /etc/cup/printers.conf.BAK
cp /etc/sudoers /etc/sudoers.BAK
cp /backup/Dennis/linux/administration/custom_file_backups/rc.* /etc/rc.d
cp /backup/Dennis/linux/administration/custom_file_backups/wpa_supplicant.conf /etc/
cp /backup/Dennis/linux/administration/custom_file_backups/blacklist /etc/modprobe.d/
cp /backup/Dennis/linux/administration/custom_file_backups/bash /root/.bashrc
cp /backup/Dennis/linux/administration/custom_file_backups/smb.conf /etc/samba/
cp /backup/Dennis/linux/administration/custom_file_backups/printers.conf /etc/cups/
cp /backup/Dennis/linux/administration/wallpaper/*.jpg /usr/share/wallpapers/
chmod -x /etc/profile.d/bsd-games-login-fortune.sh

#Editing /etc/sudoers for the purpose of adding shutdown group so users
#can shut off the computer. 
chmod +w /etc/sudoers
echo "%wheel ALL=(ALL)       NOPASSWD: ALL" >> /etc/sudoers
echo "***Adding shutdown group for users to shut down***"
groupadd shutdown
echo "%shutdown localhost=/sbin/shutdown -h now" >> /etc/sudoers
echo "%shutdown localhost=/sbin/reboot" >> /etc/sudoers
chown root:shutdown /sbin/halt
chown root:shutdown /sbin/poweroff
chown root:shutdown /sbin/reboot
chown root:shutdown /sbin/shutdown
chmod 440 /etc/sudoers


# Use wicd instead of stock /etc/rc.d/inet1 network connections
TITLE="disable slackware and install WICD"
question
if test "$OUTCOME" = "y" ; then
	chmod -x /etc/rc.d/rc.inet1
	installpkg /backup/Dennis/linux/wireless/wicd*.tgz
	echo "ifconfig lo up" >> /etc/rc.d/rc.local

fi

#Install personal packages from usb hdd
TITLE="install personal packages"
question
if test "$OUTCOME" = "y" ; then
	installpkg /backup/Dennis/linux/tgz/*.tgz
	cp /backup/Dennis/linux/administration/custom_file_backups/kismet.conf /etc/kismet/
 fi

#Install games from usb hdd
TITLE="install games"
question
if test "$OUTCOME" = "y" ; then
	installpkg /backup/Dennis/linux/games/*.tgz
 fi

#***Adding users***
TITLE="add a user"
question
while test "$OUTCOME" = "y"
 do
	echo "Add a user name";read NM
	useradd -g users -G slocate,disk,cdrom,plugdev,sys,lp,shutdown -d /home/"$NM"/ -s /bin/bash -m "$NM"
	cp /backup/Dennis/linux/administration/custom_file_backups/bash /home/"$NM"/.bashrc
	cp /backup/Dennis/linux/administration/custom_file_backups/bash_profile /home/"$NM"/.bash_profile
	cp /backup/Dennis/linux/wine/backup/fullbackup.wine.tar.bz2 /home/"NM"/
	cp /backup/Dennis/linux/wine/e-Sword.desktop /home/"$NM"/Desktop/e-Sword
	tar -jxf /home/"$NM"/fullbackup.wine.tar.bz2
	rm /home/"$NM"/fullbackup.wine.tar.bz2
		TITLE="give sudoer privlidges"
		question
		if test "$OUTCOME" = "y" ; then
			useradd -G wheel "$NM"	
		fi
		#strictly for user dp
		if test "$NM" = "dp" ; then
		mkdir /home/dp/docs ; mkdir /home/dp/down
		cp -R /backup/Dennis/docs/OfficeAdmin /home/dp/docs/
		mkdir /home/dp/docs/Estimating ; mkdir /home/dp/docs/Billing ; mkdir /home/dp/docs/Contracts
		fi

	chown "$NM":users -R /home/"$NM"/
	Y="Do you want to add a password now"
	question

		if test "$OUTCOME" = "y" ; then
			passwd "$NM"
		fi
TITLE="Do you want to add another user?"
question 
 done

#add network printer
#This part needs ammending
#any suggestions???
TITLE="add a network printer"
question
if test "$OUTCOME" = "y" ; then
	lpadmin -p HP_OfficeL7580 -v smb://MOM/HPOffice
	lpadmin -d HP_OfficeL7580
fi


#adding colors to bash
TITLE="add colors"
question
#Thanks to woodsman at LQ
if test "$OUTCOME" = "y" ; then
	echo "Adding boot message colors"
	cp /backup/Dennis/linux/administration/custom_file_backups/add_colors/shell-colors /etc/shell-colors
	cp /backup/Dennis/linux/administration/custom_file_backups/add_colors/update-issue /usr/local/sbin/update-issue
	/usr/local/sbin/update-issue
	echo "Adding color to grep"
	echo "# Add color to grep" >> /etc/profile
	echo "GREP_OPTIONS='--color=auto'" >> /etc/profile
	echo "GREP_OPTIONS='--color=auto'" >> /etc/profile
	echo "GREP_COLOR='1;32'" >> /etc/profile
	echo "Adding color to man pages"
	echo "# Add color for man pages" >> /etc/profile
	echo "export PAGER=\"most\"">> /etc/profile
fi

#Providing the option to boot to gui.
TITLE="Do you want to boot to the gui (KDE)"
question
if test "$OUTCOME" = "y" ; then
	cp /etc/inittab /etc/inittab.BAK
	cat /etc/inittab | sed -e 's/id:3:initdefault:/id:4:initdefault:/' \
 	> /tmp/inittab
	mv /tmp/inittab /etc/inittab
fi
 
Old 03-01-2009, 04:37 PM   #2
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
You can edit files in place with sed using the -i option.

This is great work for a first script. Do you have previous coding experience?
I'm sure there are minor things you could change, but at a quick glance it looks really well done.
 
Old 03-01-2009, 04:41 PM   #3
GazL
LQ Veteran
 
Registered: May 2008
Posts: 6,897

Rep: Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018
Good stuff, okos.

I do something similar. I have a lot of individual scripts I keep in one directory to make each change. Doing them as individual files has the advantage of allowing me to rerun them if necessary. My mkinitrd.sh being a good example of that as I have to run that each time I do a custom kernel build.


1) sed's '-i' option is what you're looking for. Here's one of mine as an example of it in action:

Code:
root@jupiter:~/changes# cat 007_lang.sh           
#!/bin/bash
#
#   Configure locale.

# For sh, ksh, bash

sed -i -e "s/^export LANG=en_US/export LANG=en_GB/" /etc/profile.d/lang.sh

# For csh

sed -i -e "s/^setenv LANG en_US/setenv LANG en_GB/" /etc/profile.d/lang.csh
root@jupiter:~/changes#

2) I believe that if you add your userid to the power group, you'll be able to issue shutdown without the need to resort to sudo trickery.

I just hit the button on the front myself and let ACPI do the shutdown for me, so I don't bother with this.

Can't help you with no 3.
 
Old 03-01-2009, 05:39 PM   #4
trist007
Senior Member
 
Registered: May 2008
Distribution: Slackware
Posts: 1,052

Rep: Reputation: 70
Nice okos, yeah it'll be a year in March since I've been using Linux. I love it, it's just so versatile. I've broken and reinstalled my os several times as well. That's just how you learn. It's great to see progress tho. Nice script man, keep it up.
 
Old 03-01-2009, 10:20 PM   #5
okos
Member
 
Registered: May 2007
Location: California
Distribution: Slackware/Ubuntu
Posts: 609

Original Poster
Rep: Reputation: 38
Quote:
Originally Posted by GazL View Post
1) sed's '-i' option is what you're looking for. Here's one of mine as an example of it in action:

Code:
root@jupiter:~/changes# cat 007_lang.sh           
#!/bin/bash
#
#   Configure locale.

# For sh, ksh, bash

sed -i -e "s/^export LANG=en_US/export LANG=en_GB/" /etc/profile.d/lang.sh

# For csh

sed -i -e "s/^setenv LANG en_US/setenv LANG en_GB/" /etc/profile.d/lang.csh
root@jupiter:~/changes#

2) I believe that if you add your userid to the power group, you'll be able to issue shutdown without the need to resort to sudo trickery.

I just hit the button on the front myself and let ACPI do the shutdown for me, so I don't bother with this.

Can't help you with no 3.
Thanks,
Regarding the -i option, I fiddled with the command but did not seem to get the syntax correctly. However, I just followed your example which worked. The following command,
sed -i "s/red/blue/" file.txt
Changed all of the red colors to blue in a sample file.text

Regarding #2 I did not see any of the /sbin/halt /sbin/reboot files in the power group.

Quote:
Originally Posted by David the H. View Post
You can edit files in place with sed using the -i option.

This is great work for a first script. Do you have previous coding experience?
I'm sure there are minor things you could change, but at a quick glance it looks really well done.
I had learned BASIC in high school. But that was over 25 years ago.

Does anyone have suggestions regarding my 3rd question. Is there a command to search out shared printers on a network?

Last edited by okos; 03-01-2009 at 10:34 PM.
 
Old 03-02-2009, 02:05 AM   #6
acummings
Member
 
Registered: Jul 2004
Distribution: Slackware
Posts: 615

Rep: Reputation: 50
next be 1 of my "h" files (help file I can run, prints out help)

plclh

perl command line help [mostly a bunch of one liners] (also has find, sed, and others) (all files in a folder [might also do sub folders] is supposed to substitute x for y in files.

Code:
al@P5Q:~$ cat ~/bin/plclh
#!/usr/bin/perl

print <<STUFF;
# tr/\xA0/ /
perl -pi.bak -e 'tr/\\xA0/ /' filenames*

# all files in a folder
find YourDirectory -type f -print0 | xargs -0 sed -i 's/xxxx/yyyyy/g'

find . | xargs perl -p -i.bak -e 's/oldstring/newstring/g'

perl  -e 's/string/stringier/gi'  -p  -i.bak  *.html

via commandline, runs that command, replaces string with
stringier using g global and i insensitive options.
Operates on all .html files in a folder (CWD) also makes
a backup of each file prior to the operation.

# tested s/print/unlink/ to delete files
perl -MFile::Find -e 'find sub { print if /\\.txt\$/} , shift || "."'

# from cur wrk dir, recursively deletes the dir "dir_name" and underneath
perl -MFile::Path -e 'rmtree("dir_name")'

STUFF

# end
wireshark? -- printer don't "send out" anything -- so, how ya gonna find? -- call the GhostBusters. Ah, but, print server gets found on my LAN by my chatty arp ing 2wire Gateway/router. 2wire lists the print server as a device in its device list. 2wire I think uses arp to find LAN devices/computers

A DSL modem and a Linksys router with ddwrt or whatever open source firmware on it will soon replace the 2wire. 2wire does alright though, but heartbeat/chatty (I'm not one of them auto pilot Win users).

Maybe you need to record printers in a database, even if only a simple xml file as database and make available on your backups. Perl can blurt from xml to.

perlmeister (www search word) have available a sys admin and a blurt module (uses Perl to do what you did [and more] with your shell script).

Alan.
 
Old 03-02-2009, 04:00 AM   #7
mrgreedy
LQ Newbie
 
Registered: Sep 2008
Location: England
Distribution: Slackware
Posts: 15

Rep: Reputation: 0
Nice. I have all my setup instructions in a text file, but I like the idea of using a script.
 
Old 03-02-2009, 04:18 AM   #8
GazL
LQ Veteran
 
Registered: May 2008
Posts: 6,897

Rep: Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018
Quote:
Originally Posted by okos View Post
Regarding #2 I did not see any of the /sbin/halt /sbin/reboot files in the power group.
Yes, sorry, I think I gave you a bum steer there. I'm sure I read it somewhere, but you're right it doesn't seem to do the job. I'll stick to giving 1st hand answers in future.
 
Old 03-02-2009, 06:05 AM   #9
mRgOBLIN
Slackware Contributor
 
Registered: Jun 2002
Location: New Zealand
Distribution: Slackware
Posts: 999

Rep: Reputation: 231Reputation: 231Reputation: 231
Quote:
Originally Posted by GazL View Post
Yes, sorry, I think I gave you a bum steer there. I'm sure I read it somewhere, but you're right it doesn't seem to do the job. I'll stick to giving 1st hand answers in future.

GazL I think perhaps that you were thinking of the ability to shutdown the system in runlevel 4. You need to be a member of the power group to get the "Shutdown" option with the login managers.
 
Old 03-02-2009, 06:12 AM   #10
GazL
LQ Veteran
 
Registered: May 2008
Posts: 6,897

Rep: Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018
Quote:
Originally Posted by mRgOBLIN View Post
GazL I think perhaps that you were thinking of the ability to shutdown the system in runlevel 4. You need to be a member of the power group to get the "Shutdown" option with the login managers.
Ahh, I knew I'd picked up a connection between the 'power' group and shutdown somewhere. That would explain it. Thanks for that.
 
Old 03-02-2009, 02:11 PM   #11
+Alan Hicks+
Member
 
Registered: Feb 2005
Distribution: Slackware
Posts: 72

Rep: Reputation: 55
Quote:
Originally Posted by okos View Post
1. I used the sed command to edit a file for personal use. It seems that sed will not actually edit a file. From what I understand, sed streams the file in question and replaces the desired changes into a different file. I then have to move the new file to replace the original file. This seems a little awkward. There should be a better way to go about editing a file.
This is true for certain versions of sed. SNU sed can edit the file in place with the -i option, but many other versions cannot. If you ever have any plans for working on non-GNU systems such as BSD or UNIX, I suggest you learn of other ways to manage these sed tasks. Typically this requires the use of a temporary file.

Quote:
Originally Posted by okos View Post
Code:
 #!/bin/sh
#checking who is executing this script
WHO=`whoami`
if test $WHO != "root"; then
echo "You need to be in root to execute this script!"
exit
fi
This is less than ideal. Whenever coding anything, but especially when using shell scripts, you want to simplify your tests as much as possible in order to improve performance. Here, you are assigning a variable with the output of a command, then checking this variable only once in an if-else statement. This would be best done simply by checking it inside the if-else statement.

Code:
if [ ! "$(whoami)" = "root" ]; then
This is also much cleaner. In the above example, you wouldn't notice much performance gain, but in others you could see quite a bit.

Quote:
Originally Posted by okos View Post
Code:
#Confirming mounting usb drive. 
echo "***Mounting backup files ***"
if test -e /backup = "" ;  then
This is rather ugly. :-) Not only is the code difficult to read, but you're also checking to see if /backup exists. It might very well exist and be a file instead of a directory. Try this instead.

Code:
if [ -d /backup]; then
See bash(1) for more details. Look for the "CONDITIONAL EXPRESSIONS" section.

Quote:
Originally Posted by okos View Post
Code:
#Editing /etc/sudoers for the purpose of adding shutdown group so users
#can shut off the computer. 
chmod +w /etc/sudoers
This is not just dangerous, it's stupid dangerous. Do not give write permission for files like this to every user on the machine even for a limited time. Since this script only runs as root, it shouldn't be needed anyhow.

Quote:
Originally Posted by okos View Post
Code:
echo "%wheel ALL=(ALL)       NOPASSWD: ALL" >> /etc/sudoers
echo "***Adding shutdown group for users to shut down***"
You should first test to see if this line is present before adding it. I can see this get added time and time again by mistake. The following should work.

Code:
if ! grep "^%wheel.*ALL=(ALL).*NOPASSWD:.*ALL" /etc/sudoers"; then
  echo "%wheel ALL=(ALL)       NOPASSWD: ALL" >> /etc/sudoers
  echo "***Adding shutdown group for users to shut down***"
fi
Note that if you know for a fact the whitespace seperating these arguments will always be spaces (as opposed to tabs or tabs and spaces, which the default Slackware sudoers file contains) you can make this more robust by using:

Code:
grep "^%wheel[:space:]*ALL=(ALL)[:space:]*NOPASSWD:[:space:]*ALL"
This has the advantage in that it will not match groups with names such as "wheeler" or "wheels_on_the_bus" and the like.


Quote:
Originally Posted by okos View Post
Code:
if test "$OUTCOME" = "y" ; then
	chmod -x /etc/rc.d/rc.inet1
	installpkg /backup/Dennis/linux/wireless/wicd*.tgz
	echo "ifconfig lo up" >> /etc/rc.d/rc.local
fi
A better solution would be to copy to a stock rc.inet1.conf file into place. This would remove the need to chmod -x rc.inet1 (which you generally shouldn't want to do ever) and removes the need to bring lo up in rc.local. Also, consider using upgradepkg --install-new instead of installpkg. That goes for all other instances in this script where you using installpkg. I'm only gonna point it out once though.

Quote:
Originally Posted by okos View Post
Code:
#***Adding users***
	useradd -g users -G slocate,disk,cdrom,plugdev,sys,lp,shutdown -d /home/"$NM"/ -s /bin/bash -m "$NM"
	cp /backup/Dennis/linux/administration/custom_file_backups/bash /home/"$NM"/.bashrc
	cp /backup/Dennis/linux/administration/custom_file_backups/bash_profile /home/"$NM"/.bash_profile
	cp /backup/Dennis/linux/wine/backup/fullbackup.wine.tar.bz2 /home/"NM"/
	cp /backup/Dennis/linux/wine/e-Sword.desktop /home/"$NM"/Desktop/e-Sword
Consider using the "-k" option to useradd to specify a skeleton directory instead of using these individual copy operations. "-k" will copy all the contents of the directory specified into the new user's home directory for you.
 
Old 03-02-2009, 03:18 PM   #12
rworkman
Slackware Contributor
 
Registered: Oct 2004
Location: Tuscaloosa, Alabama (USA)
Distribution: Slackware
Posts: 2,559

Rep: Reputation: 1351Reputation: 1351Reputation: 1351Reputation: 1351Reputation: 1351Reputation: 1351Reputation: 1351Reputation: 1351Reputation: 1351Reputation: 1351
Quote:
Originally Posted by mRgOBLIN View Post
GazL I think perhaps that you were thinking of the ability to shutdown the system in runlevel 4. You need to be a member of the power group to get the "Shutdown" option with the login managers.
This is untested (I'm not in a position where I can test it right now), but you can likely get the same behavior from command line by doing this:

Code:
chown root:power /sbin/{shutdown,halt}
chmod 4750 /sbin/{shutdown,halt}
 
Old 03-03-2009, 12:03 AM   #13
okos
Member
 
Registered: May 2007
Location: California
Distribution: Slackware/Ubuntu
Posts: 609

Original Poster
Rep: Reputation: 38
Thanks for the great response. I appreciate the input.

Quote:
Originally Posted by +Alan Hicks+ View Post
This is true for certain versions of sed. SNU sed can edit the file in place with the -i option, but many other versions cannot. If you ever have any plans for working on non-GNU systems such as BSD or UNIX, I suggest you learn of other ways to manage these sed tasks. Typically this requires the use of a temporary file.
So perhaps it is best to use sed to >a temp file then mv the file to its proper location as I had previously done


Quote:
Code:
if [ ! "$(whoami)" = "root" ]; then
This is also much cleaner. In the above example, you wouldn't notice much performance gain, but in others you could see quite a bit.
Could you explain the coding for this, ! "$(whoami)" ?

Quote:
This is not just dangerous, it's stupid dangerous. Do not give write permission for files like this to every user on the machine even for a limited time. Since this script only runs as root, it shouldn't be needed anyhow.
As I recall, root did not have write permission either.
Perhaps chmod 700 /etc/sudoers would be a better option.


Quote:
A better solution would be to copy to a stock rc.inet1.conf file into place. This would remove the need to chmod -x rc.inet1 (which you generally shouldn't want to do ever) and removes the need to bring lo up in rc.local.
I see your point. However, what I wanted was the option to use the rc.inet1.conf that I had customized for my system. I had set it up so that wired would be option (0) and wireless is option (1) in the rc.inet1.conf. But what I found was when I booted, my computer would first obtain an IP address first from my wired connection and secondly from my wireless. It took much longer to boot. What I really wanted to do was have my computer first try to connect wired. If there was no wired connection, then and only then would it try my encrypted wireless network. And finally, unencrypted networks. As a result,I decided to go with wicd instead.


Quote:
Also, consider using upgradepkg --install-new instead of installpkg. That goes for all other instances in this script where you using installpkg. I'm only gonna point it out once though.
Great idea.

Quote:
Consider using the "-k" option to useradd to specify a skeleton directory instead of using these individual copy operations. "-k" will copy all the contents of the directory specified into the new user's home directory for you.
I could not find the -k option in man useradd.
Could you further explain? Possibly give an example?

Regarding
Quote:
if [ -d /backup]; then
Perhaps a better option would be
Quote:
if [ -d /backup/Dennis]; then
That will show if my usb drive is properly mounted.

Thanks again
okos

One last question, as in my script, I used lpadmin to add my wife's xp printer. I know in cups you can search for printers. Is there any script to do the same. Search out computers and then printers.

Last edited by okos; 03-03-2009 at 12:27 AM.
 
Old 03-03-2009, 07:50 AM   #14
metrofox
Member
 
Registered: Jan 2009
Location: Palermo, Italy
Distribution: Slackware
Posts: 236

Rep: Reputation: 37
Thank you a lot. I've really to try the "color maker" of this beauty script. Any way, it does things I wouldn't do, for example...Adding the normal user to shutdown or reboot PC is very a dangerous thing . I'll use it when I'll install slackware again. Thank you again and take in consideration all that testers say. Sometimes it is not considered by programmer, and this is the most important thing of their job. Thank you and congratulations.

Last edited by metrofox; 03-03-2009 at 07:52 AM.
 
Old 03-03-2009, 11:14 AM   #15
okos
Member
 
Registered: May 2007
Location: California
Distribution: Slackware/Ubuntu
Posts: 609

Original Poster
Rep: Reputation: 38
Quote:
Originally Posted by metrofox View Post
Thank you a lot. I've really to try the "color maker" of this beauty script. Any way, it does things I wouldn't do, for example...Adding the normal user to shutdown or reboot PC is very a dangerous thing . I'll use it when I'll install slackware again. Thank you again and take in consideration all that testers say. Sometimes it is not considered by programmer, and this is the most important thing of their job. Thank you and congratulations.
You can thank woodsman for the color.
http://humanreadable.nfshost.com/sdeg/index.htm

Regarding shutdown, I installed slack on my kids computer.
I want each of them the ability of turning off the computer themselves. I did not want to have to be called to turn off the computer for them. Runlevel 3 requires a little linux knowledge in the first place. If they are able to log in under runlevel 3. Then they should be mature enough to turn the computer off.
Furthermore, their computer has no network / internet access. So nobody can mess with their computer without having physical access.

I set it up on my own computer. However, I am the only user. Only I can gain access in the first place. In addition, I disabled the server option for startx so I think that would be a good security feature with regard to turning off the computer.

Regarding using the script, you will need to personalize it for your needs. The script as it is will not work on other slackware computers unless you have the same setup as I have.
However, if you do not have a usb drive to backup your info, you could edit the script for cdrom or a separate partition designated strictly for backup purposes.

Last edited by okos; 03-03-2009 at 11:25 AM.
 
  


Reply



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
passing variable from bash to perl in a bash script quadmore Programming 6 02-21-2011 04:11 AM
Strange if statement behaviour when using bash/bash script freeindy Programming 7 08-04-2008 06:00 AM
DCOPserver, yea again, WHY??? joewee SUSE / openSUSE 0 10-28-2006 11:46 AM
Oh Yea, Slack 9 -Juke Box 320mb Slackware 0 09-03-2003 07:30 PM
o yea and disk druid Spaz17 Linux - Newbie 1 07-04-2003 10:14 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 10:08 PM.

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