sudo and expansion


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers sudo and expansion
# 1  
Old 01-21-2009
sudo and expansion

Hi there,
Can anyone explain me the following behavior?
Code:
hfserver:~# ls -l /home/cronlogs/mysqldump*
-rw-r--r-- 1 root root 10658464 2009-01-18 03:00 /home/cronlogs/mysqldump_20090118030002
-rw-r--r-- 1 root root 10651035 2009-01-19 03:00 /home/cronlogs/mysqldump_20090119030001
-rw-r--r-- 1 root root 10662462 2009-01-20 03:00 /home/cronlogs/mysqldump_20090120030001
-rw-r--r-- 1 root root 10680731 2009-01-21 03:00 /home/cronlogs/mysqldump_20090121030001

santiago@hfserver:~$ sudo ls -l /home/cronlogs/mysqldump*
ls: /home/cronlogs/mysqldump*: No such file or directory

When logged as root, I can display the files matching the pattern but when using sudo, it fails.
Important to mention, /home/cronlogs can only be read by root :
Code:
hfserver:~# ls -l /home
drwx------ 2 root     root     12288 2009-01-21 15:24 cronlogs

But sudo is root so why does it fail?

Thanks for your help
Santiago
# 2  
Old 01-21-2009
The problem is that not ls does the parameter expansion but the shell. But since cronlogs isn't readable by your user, the shell can't expand.
# 3  
Old 01-21-2009
Thanks for the explanation, I think I understand.
So how can I sudo this command without having to log as root?
# 4  
Old 01-22-2009
Try sudo 'bash -c "ls -l /home/cronlogs/mysqldump*"'
Substitute bash with a shell of your choice if necessary
# 5  
Old 01-22-2009
Thanks pludi.
It works but I had to remove the quotes around bash command:
Code:
sudo bash -c 'ls -l /home/cronlogs/mysqldump*'

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Use parameter expansion over a parameter expansion in bash.

Hello All, Could you please do help me here as I would like to perform parameter expansion in shell over a parameter expansion. Let's say I have following variable. path="/var/talend/nat/cdc" Now to get only nat I could do following. path1="${path%/*}" path1="${path1##*/}" Here... (8 Replies)
Discussion started by: RavinderSingh13
8 Replies

2. UNIX for Dummies Questions & Answers

Expansion within cp

I have a bunch of files which I need to transfer to another location... and some of these I need to skip. For e.g. let us say the files are: cust_abc.dat cust_xyz.dat cust_def.dat and I only want to move the first two. I want to do something like: cp cust_.dat <target> ... (1 Reply)
Discussion started by: jawsnnn
1 Replies

3. Shell Programming and Scripting

sudo: sorry, you must have a tty to run sudo

Hi, Have a need to run the below command as a "karuser" from a java class which will is running as "root" user. When we are trying to run the below command from java code getting the below error. Command: sudo -u karuser -s /bin/bash /bank/karunix/bin/build_cycles.sh Error: sudo: sorry,... (8 Replies)
Discussion started by: Satyak
8 Replies

4. Shell Programming and Scripting

sudo: sorry, you must have a tty to run sudo

Hi All, I running a unix command using sudo option inside shell script. Its working well. But in crontab the same command is not working and its throwing "sudo: sorry, you must have a tty to run sudo". I do not have root permission to add or change settings for my userid. I can not even ask... (9 Replies)
Discussion started by: Apple1221
9 Replies

5. Shell Programming and Scripting

ssh foo.com sudo command - Prompts for sudo password as visible text. Help?

I am writing a BASH script to update a webserver and then restart Apache. It looks basically like this: #!/bin/bash rsync /path/on/local/machine/ foo.com:path/on/remote/machine/ ssh foo.com sudo /etc/init.d/apache2 reloadrsync and ssh don't prompt for a password, because I have DSA encryption... (9 Replies)
Discussion started by: fluoborate
9 Replies

6. AIX

sudo log and sudo auditing

Sudo In AIX, how to find out what commands have been run after a user sudo to another user? for example, user sam run 'sudo -u robert ksh' then run some commands, how can I (as root) find what commands have been run? sudo.log only contains sudo event, no activity logging. (3 Replies)
Discussion started by: jalite19
3 Replies

7. UNIX for Dummies Questions & Answers

Unable to use the Sudo command. "0509-130 Symbol resolution failed for sudo because:"

Hi! I'm very new to unix, so please keep that in mind with the level of language used if you choose to help :D Thanks! When attempting to use sudo on and AIX machine with oslevel 5.1.0.0, I get the following error: exec(): 0509-036 Cannot load program sudo because of the following errors:... (1 Reply)
Discussion started by: Chloe123
1 Replies

8. Shell Programming and Scripting

Need to print the expansion of the found string (the expansion is beween two delimiters '-' , '||'

Hi , could anyone help me out with this problem. sample.txt has this content : u001- this is used for project1 || u002- this is used for p2|| not to be printed u003- this is used for project3 || u004- this is used for p4 || u005- this is used for project5 || u006- this is used for p6... (9 Replies)
Discussion started by: Balaji PK
9 Replies

9. Shell Programming and Scripting

~ expansion in printf

Hi, I have a script that at one point prints to a file as follows: printf -- $2 > ~/.mydir/$1 The idea is to print to a hidden directory .mydir in my home directory. I've already sanitized the inputs and $1 is in the format path1/path2/filename and $2 is some user input. When I run this... (2 Replies)
Discussion started by: Rledley
2 Replies

10. AIX

AIX Expansion CD

Hey Anyone have a copy of the Expansion CD for the old 5.1 Version of AIX Thanks (0 Replies)
Discussion started by: almuwatta
0 Replies
Login or Register to Ask a Question