LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 02-17-2008, 03:21 PM   #1
Goose1
LQ Newbie
 
Registered: Aug 2006
Posts: 4

Rep: Reputation: 0
Howto pass an argument to alias of a script?


Hi,
I have a script that needs to run as root. I have an alias for it:
alias my_script='su -c /path/path/path/my_script.sh \$*'

Now, I've added to the script some options that can be given as parameters from the command line. for example:
/path/path/path/my_script.sh 123

This works fine, but the alias doesnt pass that correctly...
$ my_script 123
su: user 123 does not exist
$

I've tryed all kind of combinations of "" '' `` but it didnt worked.
Can someone please advise?
Thanks!
 
Old 02-17-2008, 06:14 PM   #2
rhapsody630
LQ Newbie
 
Registered: Jul 2005
Posts: 3

Rep: Reputation: 0
You need to change your alias
> alias my_script='su -c /path/path/path/my_script.sh \$*'

to
alias my_script='su -c /path/path/path/my_script.sh root'

Read the man page for su. The first argument, if given, is the user to su to.

The clue is in the error message
> su: user 123 does not exist
Your alias is passing 123 and su assumes that is the user.

You don't need the \$*.

You might do better to add the script that has to be run as root to those that sudo knows about, see visiudo, and use alias my_script="sudo my_script" instead.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
How to pass argument to vpnc in F8 to acknowledge connection nolebrink Fedora 0 12-04-2007 10:56 AM
perl pass regex check as an argument lord-fu Programming 2 08-29-2007 02:55 PM
Pass argument between php scripts gandalf_the_grey Linux - Newbie 1 02-03-2006 02:53 PM
How to pass an argument to DHCPCD ? shazam75 Linux - Networking 3 02-27-2005 10:34 AM
PHP pass argument to shell script monzter Programming 2 08-14-2004 06:16 AM


All times are GMT -5. The time now is 06:04 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration