"sudo su && somecommand" doesn't run somecommand
If you are trying to run the df
command as root, you should instead do sudo df
.
This is because with sudo su && df
, you are basically executing sudo su
first and then df
.
Also make sure, your jenkins user can be sudo without password.
The sudo su
launches a second shell, and the command containing the && df
is waiting to be executed in the non-root shell, just after the sudo su
shell exits successfully.
This could be what you're looking for:
sh -c 'sudo su - root -c "df"'
Edit: please note that I don't normally use or advocate the use of sudo su - root -c
type of constructions. However, I have seen rare cases in which a program doesn't work properly when called via sudo/gksudo
, but does work properly when called via su/gksu
-- in such cases, a given user should try to use sudo -i
first, and if that does not work, one might have to resort to sudo su - root -c
or similar, as a workaround of sorts to deal with a "misbehaving" program. Since the OP used some similar syntax on his post, I assumed that his case could be such a workaround case, so I maintained the sudo su - root -c
type of structure on my answer.