Saving a temporary output within a script


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Saving a temporary output within a script
# 1  
Old 06-04-2011
Saving a temporary output within a script

Good morning everyone,

i am looking to know how to save the output of a command and reuse it again within a script

i already tired this one but it didn't work

Code:
TEMPDIR=/dir1/dir2
 
My_command> $TEMPDIR/$TEMPFILE
 
rm $TEMPDIR/$TEMPFILE*

it keeps saying "cannot write to a directory"
# 2  
Old 06-04-2011
Code:
temp=`My_command`
echo "$temp"

# 3  
Old 06-04-2011
Quote:
Originally Posted by bartus11
Code:
temp=`My_command`
echo "$temp"

thanks alot i just need to reuse the temp output with another script as i have in the follwing

Code:
#!/bin/bash 
echo "Enter value: " 
read x 
my_command | awk -vx=$x '$1>=x{print $NF}'

so i wanna run another script within my script

for example

Code:
#!/bin/bash
TEMPDIR=/dir1/dir2 
echo "Enter value: " 
read x 
my_command | awk -vx=$x '$1>=x{print $NF}' > $TEMPDIR/$TEMPFILE
 
for i in ` $TEMPFILE`
;do
 
shutdown_script $i
 
done
 
rm $TEMPDIR/$TEMPFILE*

this TEMPFILE suppose to contain the following

process1
process2
process3
process4

so i need to run another script which is (shutdown_script) within my script and now i want the shutdown_script perform the following (shutting down the processes one by one)

shutdown_script process1
shutdown_script process2
shutdown_script process3
shutdown_script process4

actually i don't know how to do that but i am still trying

i need your help guys Smilie

Last edited by Portabello; 06-05-2011 at 04:46 AM..
# 4  
Old 06-05-2011
Try:
Code:
#!/bin/bash
TEMPDIR=/dir1/dir2 
echo "Enter value: " 
read x 
my_command | awk -vx=$x '$1>=x{print $NF}' > $TEMPDIR/$TEMPFILE
 
while read i; do
  shutdown_script $i
done < $TEMPDIR/$TEMPFILE
 
rm $TEMPDIR/$TEMPFILE*

# 5  
Old 06-05-2011
Quote:
Originally Posted by bartus11
Try:
Code:
#!/bin/bash
TEMPDIR=/dir1/dir2 
echo "Enter value: " 
read x 
my_command | awk -vx=$x '$1>=x{print $NF}' > $TEMPDIR/$TEMPFILE
 
while read i; do
  shutdown_script $i
done < $TEMPDIR/$TEMPFILE
 
rm $TEMPDIR/$TEMPFILE*

it keeps saying "cannot write to a directory" =(
at line 5

---------- Post updated at 10:30 AM ---------- Previous update was at 08:32 AM ----------

i have tried the following
Code:
temp=`my_command | awk -vx=$x '$1>=x{print $NF}'`
echo "$temp"

the command (( my_command | awk -vx=$x '$1>=x{print $NF}' )) show the processes line by line just like the following

process_2
process_3
process_4
process_5

but the temp is showing the processes as a single line

process_2 process_3 process_4 process_5

Last edited by Portabello; 06-05-2011 at 11:43 AM..
# 6  
Old 06-05-2011
Does /dir1/dir2 exist?
If so, do you own enough rights to write into it?
I don't see any references to $TEMPFILE in your samples scripts.
And $TEMPDIR/$TEMPFILE can be merged to $TEMPFILE alone for simplicity, ex:
TEMPFILE='/dir1/dir2/tempfile', but it's up to you to choose if you want to have tempdir and tempfile separates, that does not affect the script at all.

Last edited by tukuyomi; 06-05-2011 at 01:46 PM..
# 7  
Old 06-05-2011
Quote:
Originally Posted by tukuyomi
Does /dir1/dir2 exist?
If so, do you own enough rights to write into it?
I don't see any references to $TEMPFILE in your samples scripts.
And $TEMPDIR/$TEMPFILE can be merged to $TEMPFILE alone for simplicity, ex:
TEMPFILE='/dir1/dir2/tempfile', but it's up to you to choose if you want to have tempdir and tempfile separates, that does not affect the script at all.
Thanks Alot tuku =)

well the directory does exist and i have full permissions on that directory
but anyways i came up with something else as i have explained in my last post

i still have a problem running the (shutdown_script) with the processes line by line

i don't know how to run the (shutdown_script) on the processes which is the output of the command i have saved in the temp variable since the output sorted incorrectly

i just want to know how to saprate the processes on each line so maybe the (shutdown_script) will work proparly, but i am still not sure it will work in that case, but it worth trying


thanks again Smilie
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed command is saving output as blank file

Hi, I am working on a script where I am adding adding colors to few of the info in the output. Now , after that is done , I see colour codes in log files which I don't want to see.:mad::mad::mad::mad: So , I tried using sed command in script as below which gives me o/p (new.log) as blank file... (7 Replies)
Discussion started by: Dream4649
7 Replies

2. Shell Programming and Scripting

Saving files with file name as output

Hi, i need help with a file creation of an output program. I've got a program that with #find creates an output for each files in a directory. If i give this command : -o spec$(date -u +%Y%m%dt%H%M) it creates just one file, overwriting all the others since it is the creation date .... (2 Replies)
Discussion started by: Board27
2 Replies

3. Shell Programming and Scripting

looping and saving output of each line separately

I have been trying this program for a long time. I am trying to read a file named "odon" line by line; read the first line, send it to do a command saved in a file "perm", once the first line has finished going through the content of the file perm, the result is saved with the number of the line.... (17 Replies)
Discussion started by: iconig
17 Replies

4. Shell Programming and Scripting

Need some Help for file filteration and saving the output in other directory

Hi all........ Plss do help me.......in a big trouble... :wall::wall::wall: I have 3 directories named as :1. /home/shuchi/source 2./home/shuchi/destination 3./home/shuchi/filter now the problem is /home/shuchi/source has say 2 files with extension .txt as given below : A.txt msisdn ... (5 Replies)
Discussion started by: ektubbe
5 Replies

5. Shell Programming and Scripting

Need some Help for file filteration and saving the output in other directory using grep....plz ...

Hi all........ Plss do help me.......in a big trouble... :wall::wall::wall: I have 3 directories named as :1. /home/shuchi/source 2./home/shuchi/destination 3./home/shuchi/filter now the problem is /home/shuchi/source has say 2 files with extension .txt as given below : A.txt Code: ... (0 Replies)
Discussion started by: ektubbe
0 Replies

6. Shell Programming and Scripting

saving output from bash into a file

I am ssh to many servers to get some information... however sometimes the server is unreacheable and i am getting an error. I want to save that output to a file but I am not able to do so... I want to be able to save output of bash into a file.. so when I run this command on a script ssh... (5 Replies)
Discussion started by: eponcedeleonc
5 Replies

7. Shell Programming and Scripting

ssh to multiple hosts and saving the output in the local host

hi I have a script to login from a host "A" to a list of hosts in a file and perform some commands inside it...its somethin like this for i in `cat file` do ssh -t $i " command1 ; command2; ..." done I wanna save the outputs in a file in the current host "A" i.e from where I am... (3 Replies)
Discussion started by: ningy
3 Replies

8. UNIX for Dummies Questions & Answers

saving command output to a variable

Hello, I have a shell script containing a command string in the following format: command1 | command2 | cut -c9-16 The output from this is a record number (using characters 9-16 of the original output string) e.g. ORD-1234 I wish to save this value to a variable for use in later commands... (4 Replies)
Discussion started by: philjo
4 Replies

9. Shell Programming and Scripting

Saving output from awk into a perl variable

How would I pass awk output to a perl variable? For example, I want to save the value in the 4th column into the variable called test. My best guess is something as follow, but I am sure this isn't correct. $test = system("awk '/NUMBER/{print \$4}' $_"); (8 Replies)
Discussion started by: userix
8 Replies

10. UNIX for Dummies Questions & Answers

Help regarding saving information within a script!

I have 2 files. File 1 exports variables globally, File 2 pulls in the information into itself and displays it. I need to know how to then save the information into the bottom of File 2, allowing for more information to be added at a later date. The scripts i've written are below. File 1:... (8 Replies)
Discussion started by: phproxy
8 Replies
Login or Register to Ask a Question