Unix Shell - su in scripts

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > January 2006 > su in scripts





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author su in scripts
Mr_Bill

2006-01-29, 9:31 pm

A wrote a simple script to mv libflashplayer.so
so I could turn flash off and on.
(Bet we are covering new ground here )

~/bin> cat flasher

#!/bin/bash
#flasher
clear

if [ -f /usr/lib/browser-plugins/libflashplayer.so ]
then
mv /the/path/libflashplayer.so /the path/libflashplayer.so.bak
echo "FlashPlayer is now OFF"

else
mv /the/path/libflashplayer.so.bak /the/path/libflashplayer.so
echo "FlashPlayer is now ON"
fi


Anyway, it works fine if I su and run the script
su -c flasher works even better.

I wanted to put the su in the script (above the if [....].
When I do, I get a permission error.

From what I understand, this is an su scope issue.

Is there a way to overcome it?

Thanks,
Mr_Bill

Chris F.A. Johnson

2006-01-29, 9:31 pm

On 2006-01-27, Mr_Bill wrote:
> A wrote a simple script to mv libflashplayer.so
> so I could turn flash off and on.
> (Bet we are covering new ground here )
>
> ~/bin> cat flasher
>
> #!/bin/bash
> #flasher
> clear


Why bother clearing the screen when you are just going to print a
single line?

> if [ -f /usr/lib/browser-plugins/libflashplayer.so ]
> then
> mv /the/path/libflashplayer.so /the path/libflashplayer.so.bak
> echo "FlashPlayer is now OFF"
>
> else
> mv /the/path/libflashplayer.so.bak /the/path/libflashplayer.so
> echo "FlashPlayer is now ON"
> fi


You should check for success of mv before printing:

mv /the/path/libflashplayer.so.bak /the/path/libflashplayer.so &&
echo "FlashPlayer is now ON" || echo "Problem"

> Anyway, it works fine if I su and run the script
> su -c flasher works even better.
>
> I wanted to put the su in the script (above the if [....].
> When I do, I get a permission error.
>
> From what I understand, this is an su scope issue.
>
> Is there a way to overcome it?


Use sudo not su.

--
Chris F.A. Johnson, author | <http://cfaj.freeshell.org>
Shell Scripting Recipes: | My code in this post, if any,
A Problem-Solution Approach | is released under the
2005, Apress | GNU General Public Licence
Mr_Bill

2006-01-29, 9:31 pm

On Fri, 27 Jan 2006 05:04:45 -0500, Chris F.A. Johnson wrote:

> You should check for success of mv before printing:
>
> mv /the/path/libflashplayer.so.bak /the/path/libflashplayer.so &&
> echo "FlashPlayer is now ON" || echo "Problem"
>


>
> Use sudo not su.


Thanks for the tips, Chris!
I'll give it a try.

Mr_Bill
Kurt Swanson

2006-01-29, 9:31 pm

Mr_Bill <No_thanks@null_mail.org> writes:
> A wrote a simple script to mv libflashplayer.so
> so I could turn flash off and on.


I know this is exacting what you were asking, but Firefox has an
extension, "Flashblock":

"Flashblock is an extension for the Mozilla, Firefox, and Netscape
browsers that takes a pessimistic approach to dealing with
Macromedia Flash content on a webpage and blocks ALL Flash content
from loading. It then leaves placeholders on the webpage that allow
you to click to download and then view the Flash content."

See http://flashblock.mozdev.org/. I used to use your rapid-fire
install/uninstall technique for years. This works a lot better--you
know when flash is available, and can activate a single (of possibly
many) flash objects on a page; you can have settings to always allow
flash from certain sites, etc.
--
© 2005 Kurt Swanson AB
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com