How to execute chsh using a bash script I put up in github?

喜欢而已 提交于 2019-12-14 01:55:20

问题


I have a gist that I always use to install the packages I need on a fresh server.

http://gist.github.com/4372049

All I need to do is to type the following in the fresh server via ssh

bash -c "$(curl -fsSL https://raw.github.com/gist/4372049)" <mysqlPassword>

I will be good to go.

Now I have this series of steps I always need to perform on a fresh installation of ubuntu.

first at root i did a

echo $SHELL
I saw that I have /bin/bash

then i switch to www-data

sudo su www-data
then i do a

echo $SHELL
I saw that I had

/bin/sh
instead.

So I did a

chsh -s /bin/bash
I was prompted for my www-data password so I gave it.

Password:
after that I switch back to root

exit
then i log back into www-data

sudo su www-data
I checked the $SHELL again

echo $SHELL
I saw that now it is

/bin/bash

listed here in https://askubuntu.com/a/232663/10591

Is there a way to write a bash script I can put up in gist.github.com to use in a similar way to execute?

if so, how do I write the bash script?

UPDATE:

I realized that I was given a vote to close this question because it was deemed too localized.

Let me rephrase this to

how do I write a bash script that I can put up in gist and use it in my linux console such that it can take in arguments for username and password and therefore execute the command

chsh -s /bin/bash 

and supplying the password correctly?

This is my attempt: https://gist.github.com/simkimsia/5126919

the su worked, but not the chsh command

Update 2:

I have changed the script to be

EXPECTEDARGS=1
if [ $# -ne $EXPECTEDARGS -o "x$0" == "x"  -o $0 == "bash" ]; then
  echo "Usage:"
  echo "   Parameter 1: your username"
  echo "   Parameter 2: your password"
  exit 1
fi

CHANGESHELL_FOR_USER=$0
PASSWORD_OF_USER=$1

########################################
## switch to another user
## read this https://stackoverflow.com/a/1988255/80353
########################################
sudo -u $CHANGESHELL_FOR_USER -H sh -c "chsh -s /bin/bash" 

expect "*?assword:*" {send -- "$PASSWORD_OF_USER\r";}
expect eof

after reading how to use a shell script to supply a password when the interface asks for it

and

https://stackoverflow.com/a/1988255/80353

Now the problem is somehow sending the password when prompted for

Password: 

回答1:


As long as you are running the below command as root, you will be fine.

chsh -s /bin/bash <username>

in this case, it is

chsh -s /bin/bash www-data

See https://gist.github.com/simkimsia/4372049#file-installation-12-10-ubuntu-sh-L373



来源:https://stackoverflow.com/questions/15307289/how-to-execute-chsh-using-a-bash-script-i-put-up-in-github

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!