Sponsored Content
Top Forums Shell Programming and Scripting Script for running root based C++ code Post 302704841 by nrjrasaxena on Monday 24th of September 2012 09:39:43 AM
Old 09-24-2012
Hi,
It is working. I found a typo..:P :P

Thanks Smilie

---------- Post updated 2012-09-24 at 08:39 AM ---------- Previous update was 2012-09-23 at 04:06 PM ----------

Hi Corona,
I wrote a complete script to fulfill my requirement [1]. It seems that I am making some mistake. It is throwing following error:
Code:
  Mon Sep 24 15:34:08 CEST 2012
./DataMC.sh: line 55: syntax error near unexpected token `exit'
./DataMC.sh: line 55: `    exit 0'

I guess, root based application does not need "exit 0", but then how shall I exit it.

Thanks

[1]
Code:
  #!/bin/bash 
date

FILENAME=$1

usage () {
    echo "Script to Run TwoTrees Function"
    echo "      ==Possible options=="
    echo "  loop    - For making DataMcPlot"
    echo "  pileup  - For PU plot"
    echo "  vtx     - For Vtx plot (Normazed to Unity w/o selection)"
    echo "  help                  - shows this help"
    echo "Example:   ./DataMC.sh option"
}

#For Running Loop()
RunLoop() {
root -l <<EOF
.L  TwoTrees.C++
TwoTrees t  
t.Loop()
.q 
EOF
}

#ForMakingPU 
MakePU() {
root -l <<EOF
.L  TwoTrees.C++                                                                                                                                     TwoTrees t
t.ToCheckPUReweight() 
EOF
}

#ForMakingVtx
MakeVtx() {
    root -l <<EOF
.L TwoTrees.C++
TwoTrees t
t.ToCheckVtx()
EOF
}

if [ $# -lt 1 ]; then
    usage
    exit 1
fi

if [ $1 = "help" ]; then
    usage
    exit 0

#For DataMC match
elif [ "$1" = "loop" ]; then
    RunLoop()
    exit 1

#For PU plot [normalized to unity && w/o selection]
elif [ "$1" = "pileup" ]; then
    MakePU()
    exit 0

#For vtx plot [normalized to unity && w/o selection]
elif [ "$1" = "vtx" ]; then
    MakeVtx()
    exit 0
fi

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Run non-root script as root with non-root environment

All, I want to run a non-root script as the root user with non-root environment variables with crontab. The non-root user would have environment variables for database access such as Oracle or Sybase. The root user does not have the Oracle or Sybase enviroment variables. I thought you could do... (2 Replies)
Discussion started by: bubba112557
2 Replies

2. Shell Programming and Scripting

Running a command or script as root

I'm writing an application (Progress language) that needs to: 1) load the contents of a cron table into the Progress application; 2) display this information in a human manner and allow a select group of people to update it (these people are logged in as themselves, not as root); 3) save... (3 Replies)
Discussion started by: rm-r
3 Replies

3. Shell Programming and Scripting

As root , running script as different user with su - problem

Dear All I am running into a situation where I am running a script as another user lets say oracle using su command as below, and the script fails because the .profile of oracle is not executed so the environment variables are not set. cat /etc/passwd | grep oracle... (4 Replies)
Discussion started by: dbsupp
4 Replies

4. Cybersecurity

Running script through SSH as root

Hi all, I have a situation where I have a shell script that I need to run remotely on multiple *nix machines via SSH. Unfortunately, some of the commands in it require root access. I know that best practices for ssh entail configuring it so that the root account cannot log in, you need to... (4 Replies)
Discussion started by: irinotecan
4 Replies

5. Shell Programming and Scripting

Issue running script as root

1) Environment:Red Hat Linux, bash shell Script to be run owned by user :myUser Home environment of myUser: pathto/home 2) ESP agent with root access will run JobXXX.sh su - myUser -c "/pathto/home/bin/script.sh" where script.sh has some echo statements and an exit statement in the end... (4 Replies)
Discussion started by: cj09
4 Replies

6. UNIX and Linux Applications

Getting error code when running the script 2 (RC)2

hi All, we have a script to remove the files from particular path,when we tryingto run manually the script went to success and removed the files but the same script which is running by other team it got failed and giving the error "2 (RC)2 "..what is the cause of the failure..and we passing the... (2 Replies)
Discussion started by: nagavenkatesh
2 Replies

7. Shell Programming and Scripting

Need to run a bash script that logs on as a non-root user and runs script as root

So I have a script that runs as a non-root user, lets say the username is 'xymon' . This script needs to log on to a remote system as a non-root user also and call up a bash script that runs another bash script as root. in short: user xymon on system A needs to run a file as root user and have... (2 Replies)
Discussion started by: damang111
2 Replies

8. Shell Programming and Scripting

Running a script as root but with different users inside

Hi All, my script.sh has the below lines, and i need to run the script as root or wam. please tell me if this will work #!/bin/bash sudo -t wam /usr/local/wam/stopwam -r ------- this needs run as wam user /usr/local/web/stopweb -a --- this needs to run as... (18 Replies)
Discussion started by: nanz143
18 Replies

9. Shell Programming and Scripting

Root running a script calling to scp using user "xyz" is not authenticating!

Close duplicate thread. (0 Replies)
Discussion started by: denissi
0 Replies

10. Programming

Running a script as root in the script

hi all, i think i have got the solution for this but want to run it past you guys first when i run a script sometimes its necassary to sudo to root so it can create users, chmod etc etc, the normal way for me doing this is just to simply run the script as root but i have created a user... (11 Replies)
Discussion started by: robertkwild
11 Replies
escape(1)							Mail Avenger 0.8.3							 escape(1)

NAME
escape - escape shell special characters in a string SYNOPSIS
escape string DESCRIPTION
escape prepends a "" character to all shell special characters in string, making it safe to compose a shell command with the result. EXAMPLES
The following is a contrived example showing how one can unintentionally end up executing the contents of a string: $ var='; echo gotcha!' $ eval echo hi $var hi gotcha! $ Using escape, one can avoid executing the contents of $var: $ eval echo hi `escape "$var"` hi ; echo gotcha! $ A less contrived example is passing arguments to Mail Avenger bodytest commands containing possibly unsafe environment variables. For example, you might write a hypothetical reject_bcc script to reject mail not explicitly addressed to the recipient: #!/bin/sh formail -x to -x cc -x resent-to -x resent-cc | fgrep "$1" > /dev/null && exit 0 echo "<$1>.. address does not accept blind carbon copies" exit 100 To invoke this script, passing it the recipient address as an argument, you would need to put the following in your Mail Avenger rcpt script: bodytest reject_bcc `escape "$RECIPIENT"` SEE ALSO
avenger(1), The Mail Avenger home page: <http://www.mailavenger.org/>. BUGS
escape is designed for the Bourne shell, which is what Mail Avenger scripts use. escape might or might not work with other shells. AUTHOR
David Mazieres Mail Avenger 0.8.3 2012-04-05 escape(1)
All times are GMT -4. The time now is 05:18 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy