Script for running root based C++ code


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script for running root based C++ code
# 8  
Old 09-24-2012
Not sure what could be the issue..

try this...

Code:
  
SAMPLE=$2
#ForMakingPU                                                                                                                                          
MakePU() {
cat <<EOF                                                                                                                                             
.L  TwoTrees.C++                                                                                                                                      
TwoTrees t                                                                                                                                            
t.ToCheckPUReweight($SAMPLE)                                                                                                                               
.q                                                                                                                                                    
EOF                                                                                                                                                   
}

and one thing is this process accepts parameter..?
This User Gave Thanks to pamu For This Post:
# 9  
Old 09-24-2012
It worked..Smilie
Quote:
Originally Posted by pamu
Not sure what could be the issue..

try this...

Code:
  
SAMPLE=$2
#ForMakingPU                                                                                                                                          
MakePU() {
cat <<EOF                                                                                                                                             
.L  TwoTrees.C++                                                                                                                                      
TwoTrees t                                                                                                                                            
t.ToCheckPUReweight($SAMPLE)                                                                                                                               
.q                                                                                                                                                    
EOF                                                                                                                                                   
}

and one thing is this process accepts parameter..?
# 10  
Old 09-24-2012
Functions have their own parameters, $2 is something local to the function when you try and use it. If you wanted the function to have parameters, you could call it like functionname parameter1 parameter2 ...

Or you could use global variables instead.
# 11  
Old 09-24-2012
Hi Corona,
Thanks for the useful comment. Bu as I understood, If I define the variable in the starting that would be global in scope
Code:
#!/bin/bash

#Global variable ??
SAMPLE=$1   

Func()
{
NAME=$2   #local ??
}

Kindly comment,

Thanks,
# 12  
Old 09-24-2012
SAMPLE is global, $1 is not. When you call a function it gets its own $1 $2 ... variables.

Try this.

Code:
#!/bin/sh

function asdf() {
        echo "asdf's 1 is $1"
        echo "asdf's 2 is $2"
}

echo "code's 1 is $1"
echo "code's 2 is $2"
asdf
asdf a b

Code:
$ ./myscript

code's 1 is
code's 2 is 
asdf's 1 is
asdf's 2 is
asdf's 1 is a
asdf's 2 is b

$ ./myscript q w

code's 1 is q
code's 2 is 2
asdf's 1 is
asdf's 2 is
asdf's 1 is a
asdf's 2 is b

$

This User Gave Thanks to Corona688 For This Post:
# 13  
Old 09-24-2012
SmilieSmilie Perfect...Smilie

Thanks Corona,
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
Login or Register to Ask a Question