Page 2 of 4 FirstFirst 1234 LastLast
Results 11 to 20 of 32

Thread: Can we check weather the user is Admin or Normal user

  1. #11
    Join Date
    Jul 2007
    Location
    Poland
    Beans
    4,499
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: Can we check weather the user is Admin or Normal user

    is it all the script does? moving stuff to restricted directories?

    Code:
    deploy.sh:
    sudo mv $from $to
    
    
    $ ./deploy.sh
    if your question is answered, mark the thread as [SOLVED]. Thx.
    To post code or command output, use [code] tags.
    Check your bash script here // BashFAQ // BashPitfalls

  2. #12
    Join Date
    Sep 2012
    Location
    Guntur
    Beans
    Hidden!
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Can we check weather the user is Admin or Normal user

    Quote Originally Posted by Vaphell View Post
    is it all the script does? moving stuff to restricted directories?

    Code:
    deploy.sh:
    sudo mv $from $to
    
    
    $ ./deploy.sh
    No it's more than just moving

    i have to restart j boss server

    service stop jboss

    then check for the processes using
    ps ax | grep jboss
    kill all the other processes except Jboss
    then start the jboss again..

    then connect to mysql database in the server
    then using mysqldump import database from the package

    That's what i have to do

  3. #13
    Join Date
    Jul 2007
    Location
    Poland
    Beans
    4,499
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: Can we check weather the user is Admin or Normal user

    what about
    Code:
    deploy.sh:
    mv
    jboss things
    mysql things
    ...
    
    
    $ sudo deploy.sh
    if your question is answered, mark the thread as [SOLVED]. Thx.
    To post code or command output, use [code] tags.
    Check your bash script here // BashFAQ // BashPitfalls

  4. #14
    Join Date
    Sep 2012
    Location
    Guntur
    Beans
    Hidden!
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Can we check weather the user is Admin or Normal user

    Quote Originally Posted by Vaphell View Post
    what about
    Code:
    deploy.sh:
    mv
    jboss things
    mysql things
    ...
    
    
    $ sudo deploy.sh
    how can a normal user can do that..
    i mean if i run the script normally in bash shell($) rather than (#)

    does it move the jboss things??

    what i want to say is. in server there are alot of users right?? if every one of them runs this script to move a certain package since this script does it automatically where lies the security they may corrupt the system so i want to check weather they are sudo or not if sudo then proceed if not Authentication failure
    Last edited by Mohan1289; October 26th, 2012 at 12:16 PM.

  5. #15
    Join Date
    Aug 2010
    Location
    Lancs, United Kingdom
    Beans
    1,588
    Distro
    Ubuntu Mate 16.04 Xenial Xerus

    Re: Can we check weather the user is Admin or Normal user

    Code:
    #!/bin/bash
    
    id=$(/usr/bin/id -u)
    
    if [ $id -ne 0 ] ; then
      echo "You must use sudo to run this script"
      exit 1
    fi
    
    # other stuff goes here...
    # mv
    # jboss things
    # mysql things
    # ...
    
    echo Done.
    Code:
    $ ./deploy.sh
    You must use sudo to run this script
    $ sudo ./deploy.sh
    Done.
    If the user tries to use sudo and fails to authenticate, your script is not called. If sudo succeeds, then they are authenticated. If the user tries to execute the script without using sudo, then they get an error message. Isn't that what you want?

  6. #16
    Join Date
    Sep 2012
    Location
    Guntur
    Beans
    Hidden!
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Can we check weather the user is Admin or Normal user

    Quote Originally Posted by spjackson View Post
    Code:
    #!/bin/bash
    
    id=$(/usr/bin/id -u)
    
    if [ $id -ne 0 ] ; then
      echo "You must use sudo to run this script"
      exit 1
    fi
    
    # other stuff goes here...
    # mv
    # jboss things
    # mysql things
    # ...
    
    echo Done.
    Code:
    $ ./deploy.sh
    You must use sudo to run this script
    $ sudo ./deploy.sh
    Done.
    If the user tries to use sudo and fails to authenticate, your script is not called. If sudo succeeds, then they are authenticated. If the user tries to execute the script without using sudo, then they get an error message. Isn't that what you want?
    Thank you but how can i kill all the remaining processes except Jboss?? how is that possible normally we will check with

    ps ax | grep jboss
    and then by using kill -9 and their pid's we will kill them but how can i do this here??

    since the pid's are dynamic how can i kill all except jboss?

  7. #17
    Join Date
    Sep 2006
    Beans
    8,627
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: Can we check weather the user is Admin or Normal user

    Can you provide some sample output from ps that shows the processes you want to kill and the process(es) you don't want to kill?

    Also, -9 is a bit heavy handed. It would give the processes a chance to shutdown gracefully if a different signal were used. TERM is the default for kill, is it not working?

  8. #18
    Join Date
    Sep 2012
    Location
    Guntur
    Beans
    Hidden!
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Can we check weather the user is Admin or Normal user

    Quote Originally Posted by Lars Noodén View Post
    Can you provide some sample output from ps that shows the processes you want to kill and the process(es) you don't want to kill?

    Also, -9 is a bit heavy handed. It would give the processes a chance to shutdown gracefully if a different signal were used. TERM is the default for kill, is it not working?
    Sorry i will give the sample of process which i don't want to kill tomorow i don't know why i can't connect to server through ssh...

    Why i said kill -9 is i don't know about the TERM signal... Thank you i will try that

  9. #19
    Join Date
    Sep 2012
    Location
    Guntur
    Beans
    Hidden!
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Can we check weather the user is Admin or Normal user

    Quote Originally Posted by Mohan1289 View Post
    Sorry i will give the sample of process which i don't want to kill tomorow i don't know why i can't connect to server through ssh...

    Why i said kill -9 is i don't know about the TERM signal... Thank you i will try that
    in this i don't want to kill last process jboss
    Attached Images Attached Images

  10. #20
    Join Date
    Sep 2006
    Beans
    8,627
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: Can we check weather the user is Admin or Normal user

    Maybe you can check using pgrep or pkill. They can take a regex pattern and the -u option allows you to specify a user.

Page 2 of 4 FirstFirst 1234 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •