Lab: Command line arguments and inputs isn’t working due to permission issue?
here the corrected code:
new_shell=$2
user_name=$1
usermod -s $user_name $new_shell
Output:
bash update_shell.sh /bin/bash adminako
usermod: Permission denied.
usermod: cannot lock /etc/passwd; try again later.
What should be the solution, please?
That output doesn’t seem to tie in with what you get without changing the script.
I get this:
bob@caleston-lp10:~$ bash update_shell.sh bob bash
usermod: user 'bash' does not exists
I would advise looking at the order of the inputs in the script, the error on the right gives a hint.
Thanks @Rosarch
Correct and I’ve changed the sequence to:
bob@caleston-lp10:~$ bash update_shell.sh /bin/bash bob
though it worked fine on my workstation with privilege of course. The command changes the user shell. In spite of switching the attribute in the Kodekloud lab, I still get the error.
----- on my workstation —
user@mintlt:~$ cat update_shell.sh
new_shell=$2
user_name=$1
usermod -s $user_name $new_shell
user@mintlt:~$ bash update_shell.sh /bin/sh adminako
usermod: no changes
user@mintlt:~$ bash update_shell.sh /bin/bash adminako
usermod: Permission denied.
usermod: cannot lock /etc/passwd; try again later.
user@mintlt:~$ sudo bash update_shell.sh /bin/bash adminako
[sudo] password for user:
user@mintlt:~$ cat /etc/passwd |grep adminako
adminako:x:1001:1001::/home/adminako:/bin/bash
This lab is a bit confusing…
What I changed to clear the check:
bob@caleston-lp10:~$ more update_shell.sh
new_shell="$2"
user_name="$1"
usermod -s $new_shell $user_name
Hi
In my case user is bob home directory, i tried command
“bash update_shell.sh /bin/sh bob” got permission denied. then i used sudo in the command,
Can you please let me know what password do we have to use here.
I don’t believe you need the password as long as the script is right it will pass on the task check.
Hi - for all labs use caleston123
as the password.
The error in the script is more of a syntax error of the usermod command.
It should be : usermod -s <new_shell absolute path> <user_name>
usermod -s /bin/bash bob
Thanks for replying.
I’m still confused, can someone please let me know what exactly the script should be.
There is a logic issue or Am I missing a step? user bob is currently logged in and how can he update the info in /etc/passwd?
bob@caleston-lp10:~$ ./update_shell.sh /bin/sh bob
usermod: Permission denied.
usermod: cannot lock /etc/passwd; try again later.