I am working on a shell script to easily manage accounts. I want to have an option to enable and disable shell access (which is easy) but the tricky part is finding if an account already has shell access so my script can show the proper options.

This is what I currently have:

Note: $account is the given account

function checkIfShellAccess
    getent passwd $account >'/bin/bash' 2>&1 && ret=true

    if $ret; then

My issue is: When I run my script and check if the user has shell access I get the following notice:

line 241: /bin/bash: Text file busy

line 241 is:

getent passwd $account >'/bin/bash' 2>&1 && ret=true

I am using: CentOS release 6.5 (Final)

Thanks for any help on this.

getent passwd $account >'/bin/bash' 2>&1 && ret=true

The above line is attempting to overwrite /bin/bash. You don't want to do that. To test for the presence of of /bin/bash in the line returned by getent, use instead:

getent passwd "$account" | grep -q '/bin/bash' && ret=true

This will work because grep sets an exit code according to whether it found the text.

There are, however, many different shells that users can use. These can include csh, ksh, and zsh. When shell access is disabled, the shell is generally set to /bin/false. If this is true on your system, consider the test:

getent passwd "$account" | grep -q '/bin/false' || ret=true
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.