Results 1 to 9 of 9
Hi. I'm trying to create a post install lockdown script to apply to multiple systems with various flavors of linux/unix (all have bash installed) and I want it to look ...
- 12-22-2010 #1Just Joined!
- Join Date
- Dec 2010
- Posts
- 10
bash conditional statements question
Hi. I'm trying to create a post install lockdown script to apply to multiple systems with various flavors of linux/unix (all have bash installed) and I want it to look in the rcx.d folders for specific files and move them from Snnxxxx to snnxxx in order to disable them.
I'm currently using a script as a base and i just need to do some modifications.
This how that part of the script looks now:
The only problem is, that the files in the rc3.d folder varies from system to system and it keeps spitting out errors when these files don't exist, which makes it a problem because it's hard to know what it did or did not do. And to manually check every system will miss the whole point of a system wide script.Code:cd /etc/rc3.d; for i in 16boot.server 50apache 75seaport 76snmpdx 77dmi 81volmgt 82initsma 84appserv 90samba; do mv ./S$i ./s$i done
What I am trying to get to is a conditional statement or something similar that will check the existence of the files (like if [ -e ]) and then execute the mv command only for the existing files. is it possible to do a loop command within the if command? Or is there an easier way to do it?
Thanks in advance
- 12-22-2010 #2
So, if I understand correctly, the only scripts you want to rename are the ones you have in that loop? If so, why not try this:
That will loop over the names you provided and only rename if they exist.Code:cd /etc/rc3.d; for i in 16boot.server 50apache 75seaport 76snmpdx 77dmi 81volmgt 82initsma 84appserv 90samba; do if [ -f "./S$i" ]; then mv ./S$i ./s$i fi done
- 12-22-2010 #3Linux Newbie
- Join Date
- Apr 2007
- Posts
- 119
you should be able to throw in an if statement to check first.
not tested, but you get the ideaCode:.... do if [ -e ./S$i ] mv ./S$i ./s$i fi done
- 12-23-2010 #4Just Joined!
- Join Date
- Dec 2010
- Posts
- 10
Thamks alot for the help, however the issue is that on some systems (Solaris 10) for some reason The apache exist as S50apache & s50apache and it will not overwrite if the files are identical
of course i can do a solaris only script, and that wont a huge hassle, but i have this thing that if i run in to a problem i MUST find the right solution. its a mental disorderCode:mv: ./S50apache and ./s50apache are identical
.
Ok I know i can solve it the manual way, but how do i do it the right way so i will have the solution in the future when i will have a need for it.
Thanks again.
- 12-23-2010 #5Linux Newbie
- Join Date
- Apr 2007
- Posts
- 119
Try using the -f flag with move so it doesn't complain if it would still fit your intention.
- 12-23-2010 #6Just Joined!
- Join Date
- Dec 2010
- Posts
- 10
I don't know why, but the -f does not work in solaris neither does -i (???)
Solaris is knida screwed up system compared to the open source *nix, it works everywhere else.
I guess I'll have to do what I really hate to do, just forget about it
.
btw, -f is default with mv cmd, and it is mentioned in man mv, anyone here use solaris and can test if that is the case on their system too?
Last edited by rabbidroid; 12-23-2010 at 02:03 PM. Reason: addition
- 12-23-2010 #7Linux Newbie
- Join Date
- Apr 2007
- Posts
- 119
How about doing a rm on the s50 version before trying the mv?
- 12-23-2010 #8Just Joined!
- Join Date
- Dec 2010
- Posts
- 10
- 12-23-2010 #9Linux Newbie
- Join Date
- Apr 2007
- Posts
- 119
You can check and see if it exists first. Then take necessary steps after.
Code:if [ -e ./s$i ] rm ./s$i fi


Reply With Quote
