General :: Storing A Variable In A Shell Script After Awk Output?

Feb 8, 2010

On command line I have no problem storing a variable e.g

Code:

:~/bin$ process=`ps -ef | awk ' $8 == "idesk" { print $2 }'`
:~/bin$ echo $process
26736
:~/bin$

When I try to incorporate this into a shell script I get a blank.

Code:

:~/bin$ cat process_idesk
#!/bin/bash
process=`ps -ef | awk ' $8 == "idesk" { print $2 }'`

[code]....

The process_idesk script has been chmoded to be executable by the user. I'm sure there must be a silly omission on my behalf.

View 3 Replies


ADVERTISEMENT

Programming :: Storing Grep Output To Feed Awk To Retrieve Entire Records Matching Variable

Jul 28, 2010

I have two files :

FileA
prot1
prot5
prot9
prot15

[Code]....

What I need to do is to extract from fileB the fields containing only the strings in fileA.

I thought awk could do the job easily with :

Code:
awk 'BEGIN { RS = "###" } /'$variable'/' fileB > output

where variable would maybe be the output of grep from fileA. So can I store the output of grep in a variable to use it afterwards with awk ?

something like that:

Code:
result=`grep prot. fileA` ; awk 'BEGIN { RS = "###" } /'$result'/' fileB > output
but that doesn't work. I'm always getting the entire fileB.

The output of grep get stored in the variable, I verified that with echo. So there is something that I just don't get... It seems to me that the above line should work.

View 11 Replies View Related

Programming :: Storing Output Of "time" Command To A Variable

Jan 21, 2011

In my script, I need to get execution time of a command (say 'ls') in mili seconds level. For this i tried using "time" command to retrieve the total execution time in milli seconds. But, the problem is that, how to save the output of time command in a variable. The format of the command is like "time ls -R /opt" Going further, the o/p of 'time' command is:

real 0m0.003s
user 0m0.004s
sys 0m0.000s

Here, in my script, I would like to use only middle line "user 0m0.004s" saved to the variable but unable to find out the way.

View 1 Replies View Related

General :: Variable Storing The Previously Executed Command?

May 23, 2010

I want to use PROMPT_COMMAND variable to build a history of all the commands i execute. So Basically i want to append the last executed command to my own command log file. How can i find the last executed command ?

I want to add PROMPT_COMMAND="echo $last_executed_command >> my_command_log" But I am not sure how to find the last executed command

View 2 Replies View Related

Debian Multimedia :: Conky Execp / Execpi To Parse Output Of Scroll Variable Generated From Shell Or PHP Scripts

Sep 11, 2015

I am having a hard time getting conky execp/execpi to correctly parse output of the scroll variable generated from shell or PHP scripts.

Code: Select allDebian 8.0
Xfce 4.10
Conky 1.9.0-6

This is a simplified minimal conky configuration file used to show the same problem:

Code: Select allalignment bottom_middle
background no
border_width 1
default_color white
default_outline_color white
default_shade_color white
double_buffer yes

[Code] ....

Here is the output I'm getting:

Code: Select all          ABC       /*doesn't scroll, UNEXPECTED, shows 10 spaces before ABC*/
          ABC       --||--
abcdefghijklmnopABC /*doesn't scroll, WORKS AS EXPECTED as scroll length is 25 which is longer than text "abcdefghijklmnop" */
abcdefghijklmnopABC --||--
abcdefghijklmnopABC /*WORKS, everything before ABC scrolls 5 characters at a time*/

View 0 Replies View Related

General :: Sed: Assigning Its Output To A Variable?

Feb 3, 2011

Kernel 2.6.21.5, GNU/Linux (Slackware 12.0).In this script,

Code:
semoi@darkstar:~$ cat rename4.sh
#!/bin/bash
INPUT="k3b_audio_0_04"

[code]...

View 3 Replies View Related

Programming :: Assign Value Of C Variable To Shell Variable?

Apr 28, 2010

included shell script inside c program, and i wanted to assign the value of c variable to shell variable..Can any one please suggest me how to do it?

View 8 Replies View Related

General :: Any Way To Store Output Of Command Into Variable?

Mar 3, 2010

I tried using the tail command in my shell script and storing that value in a variable a but an error keeps coming. Is there any other way to store the output of a command into a variable. Cannot Read text from text file and store it in a variable using shell script. The thing is I need a number from the file new.txt and use that number in my script

#!/bin/bash
a = `tail -1 new.txt|head -n 1`
echo $a

View 2 Replies View Related

General :: Assign A Variable To The Output Value Of A Program?

Feb 6, 2011

so i wrote myself a very simple hellworld program in c++

...the usual stuff
int main()
{

[code]...

View 3 Replies View Related

General :: Need To Store Output Of Bitset() In A Variable / Possible In C++?

Mar 5, 2010

I need to store the output of bitset() in a variable ... is it possible in c++?

View 1 Replies View Related

General :: Can't Save Grep Output Into Variable / Solution For This?

Feb 3, 2010

I would like to grep two numbers out of a text file, and divide them.

Here is the script code...

It feels like grep saves a new line too? or what is happening? i simply can't divide them, as it handles the variables as they are empty (and prints the two numbers although they were not printed

View 6 Replies View Related

General :: Does The Output Of The Previous Command Get Stored In Any Variable

Mar 26, 2011

For example, when using bash you can use

Code:

to execute the previous command or

Code:

!<number> to execute the Nth command(use history to see the list). Or you can use

Code:

cd !-2:1

to cd into the value in the first field that was executed 2 commands ago Anyhow, say I run a command and the output is a path. Any way to cd and then some variable where OUTPUT of the previous command was stored? A variable that always stores the OUTPUT of the last command.

View 8 Replies View Related

General :: Shell Script Variable Usage ?

Feb 9, 2010

Having real problem with below:

If I do:

I get the result I want (a file in format of <name><yyyy>-<mm>-<dd>.zip cut down to just yymmdd); but not if I try to set it as a variable ...

View 2 Replies View Related

General :: Shell Script -- Awk Variable Substitution?

Oct 7, 2010

I have a script in which I'm reading a file line by line and I'm finding certain position value using awk index as

Code:
# 2 spaces before open parens
pos=`echo | awk -v Line="$Line" '{ print index("'"$Line"'"," (")}'`

[code]....

View 2 Replies View Related

General :: Environment Variable And Current Shell

May 24, 2010

I am using Red Hat Linux Enterprise 5. I know the theory that -- using export to set environment variable, the environment variable will apply to current and child environment, but without using export to set environment variable, the environment variable will only apply to the current environment. What is the exact definition of "child environment" and "current environment"? For example,

Code:
$ var1=123
$ echo "Hello [$var1]"
The value of var1 (which is 123) is printed in shell, but I think echo is a command invoked by current shell, and it (the echo command) should be a child environment of current shell and the value of var1 should not (because not using export var1=123) impact echo.

View 13 Replies View Related

General :: Assigning Value To A Variable In Shell Script?

Nov 22, 2010

Why doesn't "var1=`echo $var2 | grep pattern`" work ?

View 8 Replies View Related

General :: Variable Declaration In Shell Scripts?

Feb 4, 2010

We have a file that declares many environmental variables. Out of which I have doubt on few. These variables are declared in UNIX environment. We are planing to migrate them along with applications to Linux.

Code:
export MAILSERVER="%new@hub"
MAIL_USERS="vinay.new"{MAILSERVER}",vijay.new"{MAILSERVER}
Does the above declarations work in Linux ?
The above declarations expands to
Code:
mail vinay.new%new@hub,vijay.new%new@hub
which looks little wierd.

[Code]...

View 4 Replies View Related

Software :: Export A Variable To Parent Shell In Shell Scripting?

May 21, 2009

Is there a way to export a variable to parent shell in shell scripting ?

View 3 Replies View Related

General :: Existence Of USER Environment Variable In The Shell?

Jan 28, 2010

I heard (although I can't find any sources for proof) that the USER environment variable may not be set in a old Unix shells (maybe even some obscure shells as well). What is the probability that it won't be set?

View 2 Replies View Related

General :: Count The Number Of Lines Inside A File And Put The Output Into A Variable?

Feb 1, 2011

i need to count the number of files and put the output into a variable. i used wc -l filename but i couldnt find an option to put the output to variable. example if the number o line is 5, i need the output of echo $x is 5.

View 3 Replies View Related

General :: Shell Script - Use Variable In A For Loop With Directory Path?

Jan 19, 2011

I modified files in several directories, and need to run a diff on the backup I created before modifying the file.

I'm trying to compose a simple shell script to speed up the task, but getting a syntax error.

Here is what I have:

for i in DIR1 DIR2 DIR3 DIR4 DIR5 do;
diff /maindir/subdir/subdir/$i/filename.txt.old /maindir/subdir/subdir/$i/filename.txt;
done

I know the paths are valid, and if I run just the diff command with the actual DIR1 instead of $i it works.

View 2 Replies View Related

General :: Create A Single Line Of Output From Multiple Variable Lines Of Input

Feb 3, 2010

I need to create a single line of output from multiple and variable lines of input in a Linux bash shell script.

My input file looks like this:

Where there may be any number of umsecondaryphonenumber lines; if there is not a umsecondaryphonenumber line for a telephonenumber, I don't want to write any output.

So, the output file should look like:

The script I have so far is:

My question is - how do print each of the elements of an array in one record - i.e. what do I put in place of howdoiprintarray?

View 2 Replies View Related

General :: Shell Script Is Showing Error After Whenever Checking A Special Variable

May 29, 2011

I have created a shell script to customise mv command, now i have achieved to accomplish all the functionality of mv by using alias. But i found difficulty in accomplish the funcionality with options [Like mv -i or mv -f etc.]. I thought about logic which check the first argument whether its starting with a minus [-] or not. if its starting with argument it will set a flag and execute accordingly. But whenever this condition is checked it shell script will throw error of destination operand missing. But the same will work with out option.

Note: I have used an minus[-] expression for decreasing a counter on the script above. The below mentioned is the portion of script. Sry for troubling Im not gud @scripting.

for i in $*
do
{
argument=`expr $argument - 1`
if [ $argument = 0 ];
then
exit
[Code]....

View 5 Replies View Related

General :: Can't See The Output Shell In Child

Feb 4, 2010

I have following script.

Code:

#!/bin/bash
export VAR="shell"
echo " $VAR in parent "
bash
echo "shell in child "

If i execute this script, the output is just

Code:

shell in parent

Why can't I see the output shell in child ?

View 2 Replies View Related

General :: Pipe Output Of Shell Command Into A New Buffer In Vim?

Jun 29, 2010

How can I pipe the output of a shell command into a new buffer in Vim? The following obviously wouldn't work, but you can see what I'm getting at:

:!echo % | :newtab

View 2 Replies View Related

General :: Copy / Paste Output From Shell (not Terminal)?

Jul 15, 2010

I often have issues starting my window manager--xfce. My computer misbehaves in one of 3 ways, one of which is to fail to open X, but generate several screens of info. I want to paste that info to this site, but since I'm in the shell, not the terminal (please correct my vocabulary if it's wrong here), I don't know how to copy and paste the output, since right-clicking doesn't give me a menu. Even if I could copy I'm not sure the information would be accessible in X. Are there any other options?

View 13 Replies View Related

General :: Displaying Graphical Output From PAM Called Shell Script

Nov 19, 2009

Before I begin I would like to say that while I am not a Linix newbie, I am not a guru or even a regular user so don't assume I have anything more than general Linux knowledge. I am carrying out research involving virtualization and Single Sign On technologies and I need to display a Xen based virtual machine to the desktop before the user is logged in. This is for a demonstration system and I am trying to find a solution that involves the least amount of system modification possible.I found a PAM module that allows for the invocation of arbitrary shell scripts which would allow me to start and display the virtual machine in question, but when trying to run the virt viewer (or any process with graphical output) I am informed that the display cannot be found. Explicitly setting the DISPLAY env to :0 before running the command has no effect.

This is where my Linux knowledge runs out. I know that there has to be some way to connect to the X session being used by the greeter, I just don't know what that method involves. The shell script is running with root privileges, so it can access whatever "X credentials" are stored locally.

I will be thankful for any assistance this forum might be able to provide, but please do not suggest alternatives to displaying a VM for my SSO needs, and please avoid any solution that involves having to write my own custom greeter. If there is absolutely no way to accomplish what I am trying to do without greeter modifications definitely tell me, but I am a security researcher, not a Linux developer so I am looking for the easiest solution to implement, even if that solution is a gross hack.

View 1 Replies View Related

General :: How To Send Colored Output Of Shell Script As Email

Feb 24, 2011

Regarding this task, I am able to print colored output in my putty sessions using tput or ASCI codes but whenever I tried to send that output through mail command to my outlook maillox, It always goes without colored. I need to produce those coloured output of the scripts as it is in mail.

View 1 Replies View Related

General :: Redirect Output Of A Command To Another File Inside Shell Script?

Aug 26, 2010

I am writing a script in which I am using AWK to append to a line in a file and save the file. The command I am using is:

Code:
awk '{s=$0; if ( NR==4 ){s=s ":/usr/java/jdk1.6.0_19/bin" } print s;}' $appName > $appName.new

[code]...

View 4 Replies View Related

General :: Write Expdp Output In A Text File Using A Shell Script ?

Feb 7, 2011

I want to write expdp output in a text file using a shell script

If i write like below:

It will write whatever is there in log file to text file

But, sometimes export fails with out start taking export (without generating log file) because of job already exists error. such times, we dont know about that error until we check manually... so i wrote like below:

But still it is not writing anything in to text file using above stmt...

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved