LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 05-02-2013, 04:15 AM   #1
Frankly3D
LQ Newbie
 
Registered: Jul 2008
Posts: 17

Rep: Reputation: 0
Question How to add separate command results together to place a file in particular location.


I have the following so far:
# rpm -qa --queryformat '%10{NAME} \n'
//* return from above has to end up in file created below. */

this creates short pretty name empty file
# hostname -s

# this is from yum.conf
~/$basearch/$releasever

returns the arch
# uname -i

# cat /etc/fedora-release
Fedora release 18 (Spherical Cow)

this is where the file is to be save
some.nfs.server://nfs/cache/*/*

How can I add all this together in one
(script\file?)
so the file will be saved in to correct nfs directory

eg: /nfs/cache/x86_64/18


Having trouble with the bash bit working so far:

#!/bin/bash

# Attempt at yum client thingy, without yum as yet.

$Var01="echo $(cat uname -i)"
$Var02="echo $(cat /etc/fedora-release | grep -o '[0-9]'*)"
$Var03="rpm -qa --queryformat '%10{NAME} \n' >> $(hostname -s)"
$Var04="$Var01"+"/($Var02)"+"/($Var03)"
$echo "$Var04"

## should end up looking something like
## /nfs/cache/x86_64/18/prettyname
## with the contents of var03 in "prettyname" file

Last edited by Frankly3D; 05-02-2013 at 07:20 AM. Reason: to clarify current progress
 
Old 05-02-2013, 08:24 AM   #2
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
It's not clear that what exactly you want to do. If you want to create a shell script then do as follow:
Code:
#!/bin/bash
Command1
Command2
Command3

CommandN
exit 0
Note: Do not use $ symbol before variable name while you're declaring it, but use $ before it when you're either printing it or using it in script:
Code:
$variable_name=$(command)    ## This is incorrect to use $ before variable name

variable_name=$(command)     ## This is the correct way
Also once add debug mode i.e. set -xv just below the #!/bin/bash in your script and invoke the script again, so you can see where your script gets stuck.

Please use [code][code] around the command's output, that you're sharing, for ease of reading.

Last edited by shivaa; 05-02-2013 at 08:30 AM.
 
Old 05-02-2013, 08:52 AM   #3
Frankly3D
LQ Newbie
 
Registered: Jul 2008
Posts: 17

Original Poster
Rep: Reputation: 0
What I attempting to do is create a cronjob. that will run the script.

The script will query releasever=18, arch=x86_64 (in this case)
The file "pretty_hostname" wil be saved to a yum server

After using the advice given:
sh yum-client.sh
x86_64/ 18/rpm -qa --queryformat '%10{NAME} \n' >> frank01 | xargs echo

spaces / 18/ need to be removed: and "pretty_name" instead of/ rpm -q...
nearly there.
 
Old 05-02-2013, 09:04 AM   #4
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
So where are you stuck? You can create a script and put it into cron file:
Code:
~$ crontab -e
x x x x x script.sh > /path/to/output_file
 
Old 05-02-2013, 11:22 AM   #5
Frankly3D
LQ Newbie
 
Registered: Jul 2008
Posts: 17

Original Poster
Rep: Reputation: 0
Nearly there:
[code]
Arch="$(uname -i )"
Release="$(cat /etc/fedora-release | grep -o '[0-9]'*)"
Host="$(hostname -s )"
Share="/${Arch}/${Release}/${Host}"
Rpms="$(rpm -qa --queryformat '%10{NAME}' \n) >> "
echo $Share
[code]

Just need to get the list of rpms to fill the file.
 
Old 05-02-2013, 12:23 PM   #6
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
Quote:
Originally Posted by Frankly3D View Post
Share="/${Arch}/${Release}/${Host}"
Rpms="$(rpm -qa --queryformat '%10{NAME}' \n) >> "
Make this part as:
Code:
Share="\/$Arch\/$Release\/$Host"
Rpms=$(rpm -qa --queryformat '%10{NAME}' \n)"
Then if you want re-direct the output of Rpms variable, then do as:
Code:
echo $Rpms >> /path/to/output_file
 
  


Reply

Tags
bash scripting, fedora, rpm


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] Output to a text file, the results of compound command Herbivore Linux - General 5 07-28-2010 10:38 AM
Are results sent to an output file only at the end of a command sequence? Zebe Linux - Newbie 2 03-19-2009 06:34 PM
How to place the output of a script in a separate terminal window SBN Linux - General 2 12-27-2008 06:38 AM
Command to separate 2nd line's 3rd word from a text file senthilvael Linux - Newbie 7 11-29-2007 11:36 PM
awk command to merge columns from two separate files into single file? johnpaulodonnell Linux - Newbie 4 01-23-2007 10:10 AM

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

All times are GMT -5. The time now is 05:32 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
Open Source Consulting | Domain Registration