LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-12-2017, 03:22 PM   #1
justmy2cents
Member
 
Registered: May 2017
Location: U.S.
Distribution: Un*x
Posts: 237
Blog Entries: 2

Rep: Reputation: Disabled
Bash Shell Script Help Please


Code:
#!/bin/bash
#Standard Operating Environment Setup Script
1 rfkill block 0pyth0
2 apt-get --purge remove thunderbird pidgin parole bluetooth 
3 adduser xubuntu1 && adduser xubuntu1 sudo
4 userdel xubuntu
5 cp -r /media/xubuntu/88D3-A937/Packages /home/xubuntu1 ; cp -r /media/xubuntu/88D3-A937/Config /home/xubuntu1 
6 mv /home/xubuntu1/Config/.* /home/xubuntu1
7 dpkg -i /home/xubuntu1/Packages/*.deb 
8 macchanger -A wlp6s0
9 cp -r /home/xubuntu1/oh-my-zsh /home/xubuntu1/.zshrc /root/
10 chsh ; chsh xubuntu1 
11 chmod go-rx /home/*
12 chmod go-r /etc/group
13 find / -perm -4000 -print -execdir chmod go-x {} \; 
14 chmod go+x /bin/su /usr/bin/sudo
15 passwd
16 echo -e "Do you wish to login as another user? [Y/n]"
17 read choice
18 if [ $choice == "Y" ]
19 then killall xfce4-session
20 else service lightdm restart
21 fi

Last edited by justmy2cents; 05-12-2017 at 04:15 PM.
 
Old 05-12-2017, 03:25 PM   #2
justmy2cents
Member
 
Registered: May 2017
Location: U.S.
Distribution: Un*x
Posts: 237

Original Poster
Blog Entries: 2

Rep: Reputation: Disabled
Can anyone please explain why in line 4 it doesn't delete the user xubuntu (note that i'm executing this as root).
 
Old 05-12-2017, 03:37 PM   #3
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,263
Blog Entries: 24

Rep: Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194
Welcome to LQ!

Does the script produce any messages when run providing clues to the reason the user was not deleted?

As usual, I would suggest reading the man page for userdel, but this is important:

Code:
man userdel

...
CAVEATS
       userdel will not allow you to remove an account if there are running processes which belong to this
       account. In that case, you may have to kill those processes or lock the user's password or account and
       remove the account later.
 
1 members found this post helpful.
Old 05-12-2017, 03:44 PM   #4
justmy2cents
Member
 
Registered: May 2017
Location: U.S.
Distribution: Un*x
Posts: 237

Original Poster
Blog Entries: 2

Rep: Reputation: Disabled
Hi Astro thank you, yeah I just figured out that "xubuntu is currently being used by a process". Thanks!!

Last edited by justmy2cents; 05-12-2017 at 03:48 PM.
 
Old 05-12-2017, 03:45 PM   #5
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,225

Rep: Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320
Start with script with "set -e" so that it exits when anything errors.
 
1 members found this post helpful.
Old 05-12-2017, 03:47 PM   #6
justmy2cents
Member
 
Registered: May 2017
Location: U.S.
Distribution: Un*x
Posts: 237

Original Poster
Blog Entries: 2

Rep: Reputation: Disabled
Quote:
Originally Posted by dugan View Post
Start with script with "set -e" so that it exits when anything errors.
Awesome tip, I'll start doing that to debug my scripts, thanks

Last edited by justmy2cents; 05-12-2017 at 03:57 PM.
 
Old 05-12-2017, 03:51 PM   #7
justmy2cents
Member
 
Registered: May 2017
Location: U.S.
Distribution: Un*x
Posts: 237

Original Poster
Blog Entries: 2

Rep: Reputation: Disabled
Also guys I wanted to use a sed command in my script to change %sudo ALL=(ALL:ALL) ALL to %sudo ALL=(root) /usr/bin/apt-get

But I don't know how to do this cus im a noob in sed.. Any advice?

Last edited by justmy2cents; 05-12-2017 at 03:56 PM.
 
Old 05-12-2017, 08:25 PM   #8
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
playing with the sudo file... hum
Code:
sed -i -e 's/%sudo ALL=(ALL:ALL) ALL/%sudo ALL=(root) /usr/bin/apt-get/g' /etc/sudoers
 
Old 05-12-2017, 08:30 PM   #9
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
Line 16-17 can be changed to one line
Code:
read -p "Do you wish to login as another user? [Y/n]" choice
make it so that it does not matter if lowercase or upper case 'y'
Code:
userx%voider ⚡ scripts ⚡> choice="y"
userx%voider ⚡ scripts ⚡> [[ ${choice^^} == 'Y' ]] && echo "hi $choice"
hi y
userx%voider ⚡ scripts ⚡>
that changes lower case to upper case. seen as error preventing in case they forget to hit the shift key to upper case the y.

you can also default assign choice='Y' Because in most scripts standard syntax for Y/n is Y = default setting.

Last edited by BW-userx; 05-12-2017 at 08:52 PM.
 
Old 05-13-2017, 03:51 AM   #10
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
Quote:
Originally Posted by justmy2cents View Post
Also guys I wanted to use a sed command in my script to change %sudo ALL=(ALL:ALL) ALL to %sudo ALL=(root) /usr/bin/apt-get
am i right to assume that you want to automate the editing of /etc/sudoers? being a confessed noob? you know that a broken sudoers means no sudo? are you sure this is a good idea? i'm not...
anyhow, other people have things to say about that:
https://stackoverflow.com/questions/...-from-a-script
i suggest you read most of it, incl. comments, before continuing.
 
Old 05-13-2017, 04:03 AM   #11
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,842

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
I have no idea if user xubuntu really exists.
 
Old 05-15-2017, 11:05 AM   #12
justmy2cents
Member
 
Registered: May 2017
Location: U.S.
Distribution: Un*x
Posts: 237

Original Poster
Blog Entries: 2

Rep: Reputation: Disabled
Code:
#!/bin/bash
#Standard Operating Environment Setup Script
1 rfkill block 0pyth0
2 apt-get --purge remove thunderbird pidgin parole bluetooth
3 adduser xubuntu1 && adduser xubuntu1 sudo
4 userdel -f xubuntu
5 chmod u+w /etc/sudoers
6 sed 's/%sudo   ALL=(ALL:ALL) ALL/%sudo   ALL=(root) \/usr\/bin\/apt-get \/usr\/bin\/dpkg/i' /etc/sudoers > ~/sudo
7 mv ~/sudo /etc/sudoers
8 chmod u-w /etc/sudoers
9 cp -r /media/xubuntu/88D3-A937/Config/.* /home/xubuntu1
10 ^/home/xubuntu1^/root
11 chown xubuntu1 .vimrc ; chgrp xubuntu1 .vimrc
12 find /home/xubuntu1 -uid 0 -execdir rm -rf {} \;
13 cp -r /media/xubuntu/88D3-A937/Packages/*.deb /root/.cache
14 dpkg -i /root/.cache/*.deb
15 macchanger -A wlp6s0
16 chsh ; chsh xubuntu1
17 chmod go-rx /home/*
18 chmod go-r /etc/group
19 find / -perm -4000 -execdir chmod go-x {} \;
20 chmod go+x /bin/su /usr/bin/sudo
21 passwd
22 read -p "Do you wish to login as another user? [Y/n]:" choice
23 if [ $choice = "Y" ]
24    then killall xfce4-session
25    elif [ $choice = "n" ]
26    then sed 's/0/1/' /etc/lightdm/lightdm.conf > ~/light ; mv ~/light /etc/lightdm/lightdm.conf ; \  
27    sed 's/xubuntu/xubuntu1/' /etc/lightdm/lightdm.conf > ~/light ; mv ~/light /etc/lightdm/lightdm.conf ; \
28    service lightdm restart
29    else echo "Invalid Option: `echo $choice`, please select [Y/n]:" 
30 fi
31 until [[ $choice == "Y" || $choice == "n" ]]  
32 do
33 read -p "Invalid Option: `echo $choice`, please select [Y/n]:" choice
34 done

Last edited by justmy2cents; 05-15-2017 at 12:54 PM.
 
Old 05-15-2017, 11:14 AM   #13
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
is that you just sharing?
 
Old 05-15-2017, 11:19 AM   #14
justmy2cents
Member
 
Registered: May 2017
Location: U.S.
Distribution: Un*x
Posts: 237

Original Poster
Blog Entries: 2

Rep: Reputation: Disabled
Hello ladies and gentlemen, can anyone tell me why sed in line 7 works on everything besides in the /etc/sudoers file? (e.g. I can make a file with %sudo All=(ALL:ALL) ALL; and it will change that, but it wont do it for /etc/sudoers). Also why in line 10 wont it modify line 9's command.. And one last thing, am I using the until loop correctly?

Last edited by justmy2cents; 05-15-2017 at 12:05 PM.
 
Old 05-15-2017, 11:21 AM   #15
justmy2cents
Member
 
Registered: May 2017
Location: U.S.
Distribution: Un*x
Posts: 237

Original Poster
Blog Entries: 2

Rep: Reputation: Disabled
Quote:
Originally Posted by BW-userx View Post
Line 16-17 can be changed to one line
Code:
read -p "Do you wish to login as another user? [Y/n]" choice
make it so that it does not matter if lowercase or upper case 'y'
Code:
userx%voider ⚡ scripts ⚡> choice="y"
userx%voider ⚡ scripts ⚡> [[ ${choice^^} == 'Y' ]] && echo "hi $choice"
hi y
userx%voider ⚡ scripts ⚡>
that changes lower case to upper case. seen as error preventing in case they forget to hit the shift key to upper case the y.

you can also default assign choice='Y' Because in most scripts standard syntax for Y/n is Y = default setting.
I decided to use a loop instead so that they have to enter the characters as specified

Last edited by justmy2cents; 05-15-2017 at 11:29 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash Shell Script Help! ChrisJames82 Linux - Newbie 11 11-07-2016 12:51 PM
Calling a bash shell script from within another script dedman Linux - Software 7 04-24-2010 08:53 PM
in bash shell how to run shell script during startup rammohan04 Red Hat 2 07-31-2009 02:07 AM
bash shell script globeTrotter Linux - Newbie 5 06-03-2004 05:07 AM
bash shell script MaryM Linux - Newbie 0 02-15-2002 11:45 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:08 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration