1828446 Members
3014 Online
109977 Solutions
New Discussion

Script addition

 
SOLVED
Go to solution
Adam W.
Valued Contributor

Script addition

Guru's I have attached a script a few of you came up with. I have a question though, How would I add a "test" to this? I think I have the correct syntax down, it is

If [[ $# != 1 ]]
then
echo â Test mode - Command would be: chown / chmodâ $FILENAME
else
perform chown/chmod
fi


But I am having trouble incorporating it into the script. Can someone help me with where to add this in, or know of an easier way?
There are two types of people in the world, Marines and those who wish they were.
16 REPLIES 16
James R. Ferguson
Acclaimed Contributor

Re: Script addition

Hi Adam:

#!/usr/bin/sh
if [ $# -ne 1 ]; then
echo "ONE argument only, please"
else
echo "OK, I saw one argument"
fi

...

Regards!

...JRF...
Michael Mike Reaser
Valued Contributor

Re: Script addition

JRF, I'd take it one step further:

#!/usr/bin/sh
if [ $# -ne 1 ]; then
echo "ONE argument only, please"
exit 99
else
echo "OK, I saw one argument"
fi

...

If not using one and only one argument, get the heck out of Dodge. :-)
There's no place like 127.0.0.1

HP-Server-Literate since 1979
Adam W.
Valued Contributor

Re: Script addition

James, pardon my ignorance here, however it would look like the attached correct? But in your statement, the else statement would only have it echo out "OK, I saw one arg." i need the else to push the chmod/chown commands.
There are two types of people in the world, Marines and those who wish they were.
Adam W.
Valued Contributor

Re: Script addition

See this is why I love ITRC. Sometimes I don't know what I would do without the knowledge you guys have.
There are two types of people in the world, Marines and those who wish they were.
James R. Ferguson
Acclaimed Contributor

Re: Script addition

Hi (again) Adam:

...
echo "TEST MODE - command would be: 'chown somebody ${FILENAME}'"
...

Regards!

...JRF...
Adam W.
Valued Contributor

Re: Script addition

OK, I have attached it. Does it look correct?
There are two types of people in the world, Marines and those who wish they were.
James R. Ferguson
Acclaimed Contributor

Re: Script addition

Hi Adam:

Please attach a TEXT file.

...JRF...
Adam W.
Valued Contributor

Re: Script addition

What text file?
There are two types of people in the world, Marines and those who wish they were.
Adam W.
Valued Contributor

Re: Script addition

oh lol Sorry about that.
There are two types of people in the world, Marines and those who wish they were.
James R. Ferguson
Acclaimed Contributor
Solution

Re: Script addition

Hi Adam:

OK, let's rewrite this now that I see (I think) where you are going and now that I have a text file that I can open and read :-)

# cat /.fixup
#!/usr/bin/sh
typeset CMD=""
[ "$1" = "-d" ] && CMD=echo
awk -F":" '$3>100 {print $3,$4,$6}' /etc/passwd | \
while read UID GID DIR X
do
for FILE in .profile .Xauthority .elm .forward .neditdb .sh_history \
.ssh2 .sw .exrc .cshrc .login .logout .env .dt
do
${CMD} chown ${UID}:$GID ${DIR}/${FILE}
${CMD} chmod 740 ${DIR}/${FILE}

done
done
exit

...run as:

# ./fixup -d

...to debug; otherwise to actually perform the work, run as:

# ./fixup

Regards!

...JRF...
Adam W.
Valued Contributor

Re: Script addition

Ok so I can run it with a -d to "test" it and without the -d to actually perform the work. Correct? Wow yours looks a lot different than the other one. LOL!
There are two types of people in the world, Marines and those who wish they were.
James R. Ferguson
Acclaimed Contributor

Re: Script addition

HI (again) Adam:

> Ok so I can run it with a -d to "test" it and without the -d to actually perform the work. Correct?

Yes.

Regards!

...JRF...
Adam W.
Valued Contributor

Re: Script addition

James, as usual, your knowledge is extremely beneficial! DOn't ever leave the forums! Thanks Again James!
There are two types of people in the world, Marines and those who wish they were.
James R. Ferguson
Acclaimed Contributor

Re: Script addition

Hi (again) Adam:

Looking again at your objective, I see two things you need to reconsider:

1. Some of the objets inyour list are directories; eg. ".sw". Making the permissions on a directory = 740 means that the group can't search the directory and you might as well make the permissions = 700 since group members are crippled.

2. If you objective is to change all of the contents of the HOME directories you find, then a _recursive_ chown() and a _recursive_ chmod() might be useful. See the manpages.

Regards!

...JRF...
Adam W.
Valued Contributor

Re: Script addition

James, I actually cought that too, and I removed the directories from the listing. However this does add one more issue. Now I need the .dt and .dtprofile directories to have 755 permissions. Good catch James, thanks for looking out.
There are two types of people in the world, Marines and those who wish they were.
Adam W.
Valued Contributor

Re: Script addition

James, I know your busy, but would you mind shooting me an e-mail? I would like to pick your brain a bit. If not I understand. Adam.Winebaugh@commandinformation.com
There are two types of people in the world, Marines and those who wish they were.