LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-03-2014, 09:16 AM   #1
madhumithamohan
LQ Newbie
 
Registered: Jul 2011
Posts: 16

Rep: Reputation: Disabled
need help in modifying the shell script


Hi

I have wrote the below script to delete old files.

But i need help in modifying it in a way that the script can login as different users in the same server.

My server has different domains and each owned by their respective application id.

This script has to be run seperately for every domain in the same server,which is not effective.Hence i want to modify in a way that the script can login in as all app id users and perform the deletion.

wlmkone@palio$ cat script3.ksh

#!/bin/sh

output=$(df -k /prod/msp/logs | tail -1 | awk '{print $4}' | sed 's/%//g'
echo $output
if [ "$output" -gt "70" ]; then
find /prod/msp/logs ! -name "STOPMASTER*" ! -name "STARTMASTER*" -type f -mtime +1 -exec ls -t {} \;
fi

wlmkone@palio$


Note: Here wlmkone is one of the application ids.The server has 6 different applications like this.
 
Old 12-03-2014, 09:59 AM   #2
sudowtf
Member
 
Registered: Nov 2013
Posts: 191

Rep: Reputation: 45
?maybe:

sudo -u username ./script3.ksh

sudo -g groupname ./script3.ksh
 
Old 12-03-2014, 11:54 AM   #3
madhumithamohan
LQ Newbie
 
Registered: Jul 2011
Posts: 16

Original Poster
Rep: Reputation: Disabled
But i need to login as user 1 first then do the deletion,again login as user 2 -perform deletion and so on for all 5 users in the same server.
 
Old 12-03-2014, 11:58 AM   #4
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 9,453

Rep: Reputation: 2777Reputation: 2777Reputation: 2777Reputation: 2777Reputation: 2777Reputation: 2777Reputation: 2777Reputation: 2777Reputation: 2777Reputation: 2777Reputation: 2777
so use sudo. That is used to run an app as another user (see man page first)
 
1 members found this post helpful.
Old 12-03-2014, 12:07 PM   #5
sudowtf
Member
 
Registered: Nov 2013
Posts: 191

Rep: Reputation: 45
it seems you could use the sudo -u -A (--askpass) from one login-shell:
Code:
sudo -u user1 --askpass ./script3.ksh
sudo -u user2 --askpass ./script3.ksh
sudo -u user3 --askpass ./script3.ksh
sudo -u user4 --askpass ./script3.ksh
sudo -u user5 --askpass ./script3.ksh
do you have root access? my suggestion is probably not the best solution. or maybe proper group rights and -g is better.
from your post it seems /prod/msp/logs is a user specific folder (maybe chrooted)? i dont quite get that.
 
Old 12-03-2014, 01:16 PM   #6
madhumithamohan
LQ Newbie
 
Registered: Jul 2011
Posts: 16

Original Poster
Rep: Reputation: Disabled
i dont have root access.

And /prod/msp/logs is one specific folder in the server (and under that all the application logs will reside)

eg:

drwxr-x--- 4 wlrchde gwlrchde 20480 Nov 25 19:05 rchde_logs
drwxr-x--- 7 wlaffnm gwlaffnm 16384 Nov 25 19:05 affnm_logs
drwxrwxrwx 5 wlbpmup gwlbpmup 12288 Nov 25 19:07 bpmup_logs
drwxr-x--- 5 wlpsssp gwlpsssp 12288 Nov 25 19:08 psssp_logs
drwxr-x--- 4 wlrdm gwlrdm 12288 Nov 25 19:18 rdm_logs
-rwxr-xr-- 1 root root 33660 Nov 25 19:50 STARTMASTER11-25-14-19:00:12.log
drwxr-x--- 6 wlrcm gwlrcm 4177920 Nov 25 19:54 rcm_logs
drwxr-xr-x 7 wlbpmsp gwlbpmsp 98304 Dec 3 14:08 bpmsp_logs
[wlbpmsp@cherokee] /prod/msp/logs

I need to login in to each app's log as its user to remove the old logs.Hence looking for one script to do that work.
 
Old 12-03-2014, 01:20 PM   #7
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 9,453

Rep: Reputation: 2777Reputation: 2777Reputation: 2777Reputation: 2777Reputation: 2777Reputation: 2777Reputation: 2777Reputation: 2777Reputation: 2777Reputation: 2777Reputation: 2777
How the rights are set on the directory itself?
 
Old 12-03-2014, 01:24 PM   #8
sudowtf
Member
 
Registered: Nov 2013
Posts: 191

Rep: Reputation: 45
if you dont have their passwords or root access then you will need to have someone assign you rights to the folder/files. otherwise what you are asking can't be done. sudo seems the easiest choice.
 
Old 12-03-2014, 11:50 PM   #9
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,354
Blog Entries: 55

Rep: Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541
Wouldn't it be easier to have each UID run its own cron job?

Example for user "wlrchde":
Code:
#!/bin/sh --
LOG_DIR="/prod/msp/logs/rchde_logs"; [ -d "${LOG_DIR}" ] || exit 1; RAW_VALUES=($(df -lkP "${LOG_DIR}")); DIR_SIZE=${RAW_VALUES[4]//%/}
[ $DIR_SIZE -gt 70 ] && { find "${LOG_DIR}" -type f ! -name "STOPMASTER*" -a ! -name "STARTMASTER*" -mtime +1 -print0|xargs -r -t -iX rm -f 'X'
# Do check here if the process needs a 'kill -HUP' after cleaning up logs.
; }; exit 0
 
Old 12-04-2014, 12:35 AM   #10
SAbhi
Member
 
Registered: Aug 2009
Location: Bangaluru, India
Distribution: CentOS 6.5, SuSE SLED/ SLES 10.2 SP2 /11.2, Fedora 11/16
Posts: 664

Rep: Reputation: 81
Quote:
LOG_DIR="/prod/msp/logs/rchde_logs"; [ -d "${LOG_DIR}" ] || exit 1; RAW_VALUES=($(df -lkP "${LOG_DIR}")); DIR_SIZE=${RAW_VALUES[4]//%/}
would fetch the headings of the output, below would be just a minor correction:

Code:
LOG_DIR="/prod/msp/logs/rchde_logs"; [ -d "${LOG_DIR}" ] || exit 1; RAW_VALUES=($(df -lkP "${LOG_DIR}"|sed '1d')); DIR_SIZE=${RAW_VALUES[4]//%/}
 
Old 12-04-2014, 12:58 AM   #11
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,354
Blog Entries: 55

Rep: Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541
Quote:
Originally Posted by SAbhi View Post
would fetch the headings of the output,
Thanks!

Could also be:
Code:
LOG_DIR="/prod/msp/logs/rchde_logs"; [ -d "${LOG_DIR}" ] || exit 1; RAW_VALUES=($(df -lkP "${LOG_DIR}")); DIR_SIZE=${RAW_VALUES[11]//%/}
if you don't want use head, grep, awk or sed.
 
1 members found this post helpful.
Old 12-11-2014, 09:27 AM   #12
madhumithamohan
LQ Newbie
 
Registered: Jul 2011
Posts: 16

Original Poster
Rep: Reputation: Disabled
Thanks for the reply.

But i need to have a single script which logs in as different users and perfrom the operation.Is it possible?.

i am tryin to use sudo,but no luck
 
Old 12-11-2014, 09:46 AM   #13
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 9,453

Rep: Reputation: 2777Reputation: 2777Reputation: 2777Reputation: 2777Reputation: 2777Reputation: 2777Reputation: 2777Reputation: 2777Reputation: 2777Reputation: 2777Reputation: 2777
so you have no root access, no sudo rights, but you need to run something as another user?
How do you want to log in as different user?
 
Old 12-11-2014, 09:55 AM   #14
madhumithamohan
LQ Newbie
 
Registered: Jul 2011
Posts: 16

Original Poster
Rep: Reputation: Disabled
I tried this...

It works..but no sure how i can put this in a single job or a script

/usr/local/bin/pbrun -u wlmkone ./script.ksh
/usr/local/bin/pbrun -u wlrchde ./script.ksh
/usr/local/bin/pbrun -u wleil ./script.ksh
/usr/local/bin/pbrun -u wlrecap ./script.ksh
/usr/local/bin/pbrun -u wlisso ./script.ksh
/usr/local/bin/pbrun -u wlclcs ./script.ksh

In which location i should place my script and where can i include all these commands under one single job/script.
 
Old 12-11-2014, 10:06 AM   #15
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 9,453

Rep: Reputation: 2777Reputation: 2777Reputation: 2777Reputation: 2777Reputation: 2777Reputation: 2777Reputation: 2777Reputation: 2777Reputation: 2777Reputation: 2777Reputation: 2777
you can put these lines into a file (one by one) and name it whatever you want. You can store it in your home/bin directory and that is the script you need to execute. You can also add
#!/bin/ksh (or similar) as the very first line, you need to add execute permission and that's all
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
[SOLVED] Modifying lines in file from the shell aihaike Linux - General 4 09-24-2013 08:18 PM
Modifying records of a file using shell scripting barunparichha Linux - Software 5 05-21-2009 09:33 AM
Modifying Specific Child Nodes In XML using Shell Script senthilmuthiah Linux - Newbie 1 04-20-2009 04:38 AM
Shell script for modifying file extensions VTGuitarMan Linux - Newbie 6 03-08-2008 07:24 PM
modifying a file in shell (via sed ?) Shautieh Programming 7 09-19-2006 05:14 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:58 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration