You are not logged in.

#1 2009-10-05 18:26:39

Afnaf
Member
From: Sweden
Registered: 2009-07-29
Posts: 27
Website

[SOLVED] Trying to get going with Bash scripting =)

Hello!

Thank you for all the answers! It ended up like this. The reason i run multiple scripts is because I am a real beginner and don't want 2000+ lines of code. That's just me. Sure, it would be lovely if a could get it all in one script but wont that be a heck lot of work putting it all together?

if 
   [ $UID -ne 0 ]; then    
   echo "************ WARNING **************"
   echo "YOU NEED TO BE ROOT TO USE THIS !"
   echo "You are just a ordinary user (but mom loves you just the same)."  # =) =) =)
   echo "************ WARNING **************"  
   exit
   clear

But now to my second problem with the users and groups menus. The problem is that I need to check if a user already exist and I think I have done it right but apparently not sad

OPTIONS="Add-user Delete-user Edit-user Return"
select opt in $OPTIONS; do
    if [ "$opt" = "Add-user" ]; then
      echo ""
      echo "Please select a username for the new account: "
      read username
      echo "And now the password: "
      stty_orig=`stty -g`
      stty -echo
      read password
      stty $stty_orig
     grepit='grep -o -m 1 ^$username /etc/passwd'
      $grepit
if
      [ "$grepit" = "$username" ]; then
      echo "This username already exist, please try again"

else

      echo "Select a primary group for the account (the group must exist): "
      read group
      echo "Are you sure you want to add this user? (y/n)"
      read yorn
fi
if [ "$yorn" = "y" ]; then
    useradd -g $group -p $password $username
    echo "$username added with the primary group $group."  
    echo ""
   fi

/ Best regards, Afnaf

Last edited by Afnaf (2009-10-10 16:08:36)

Offline

#2 2009-10-05 23:32:53

Ghost1227
Forum Fellow
From: Omaha, NE, USA
Registered: 2008-04-21
Posts: 1,422
Website

Re: [SOLVED] Trying to get going with Bash scripting =)

You know there's an easier (and much shorter) to handle the root check right? wink


.:[My Blog] || [My GitHub]:.

Offline

#3 2009-10-06 04:01:28

scragar
Member
Registered: 2009-07-14
Posts: 108

Re: [SOLVED] Trying to get going with Bash scripting =)

Ghost1227 wrote:

You know there's an easier (and much shorter) to handle the root check right? wink

[ $(whoami) = 'root' ]

Or are you thinking of something else?

Last edited by scragar (2009-10-06 04:01:39)

Offline

#4 2009-10-06 04:21:33

fukawi2
Ex-Administratorino
From: .vic.au
Registered: 2007-09-28
Posts: 6,231
Website

Re: [SOLVED] Trying to get going with Bash scripting =)

You're sleeping for 10 seconds, making the user wait 10 seconds for something that should be instant..?

You can't do what you're asking, because each script runs in it's own process, and the variables won't be shared between processes. Is there a reason you're using separate scripts instead of functions within one script?

Offline

#5 2009-10-06 04:59:48

Ghost1227
Forum Fellow
From: Omaha, NE, USA
Registered: 2008-04-21
Posts: 1,422
Website

Re: [SOLVED] Trying to get going with Bash scripting =)

scragar wrote:
Ghost1227 wrote:

You know there's an easier (and much shorter) to handle the root check right? wink

[ $(whoami) = 'root' ]

Or are you thinking of something else?

Not what I was thinking, but it'd work.


.:[My Blog] || [My GitHub]:.

Offline

#6 2009-10-06 05:36:16

fukawi2
Ex-Administratorino
From: .vic.au
Registered: 2007-09-28
Posts: 6,231
Website

Re: [SOLVED] Trying to get going with Bash scripting =)

Ghost1227 wrote:

Not what I was thinking, but it'd work.

[ $UID -ne 0 ] && exit 1

Offline

#7 2009-10-06 05:43:26

lolilolicon
Member
Registered: 2009-03-05
Posts: 1,722

Re: [SOLVED] Trying to get going with Bash scripting =)

fukawi2 wrote:
Ghost1227 wrote:

Not what I was thinking, but it'd work.

[ $UID -ne 0 ] && exit 1
[ `id -u` == 0 ] || exit `id -u`

Last edited by lolilolicon (2009-10-06 05:47:44)


This silver ladybug at line 28...

Offline

Board footer

Powered by FluxBB