-   Linux - Newbie (
-   -   How to add separate command results together to place a file in particular location. (

Frankly3D 05-02-2013 04:15 AM

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

returns the arch
# uname -i

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

this is where the file is to be save

How can I add all this together in one
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:


# 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)"
$echo "$Var04"

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

shivaa 05-02-2013 08:24 AM

It's not clear that what exactly you want to do. If you want to create a shell script then do as follow:


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:

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

Frankly3D 05-02-2013 08:52 AM

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

shivaa 05-02-2013 09:04 AM

So where are you stuck? You can create a script and put it into cron file:

~$ crontab -e
x x x x x > /path/to/output_file

Frankly3D 05-02-2013 11:22 AM

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

Just need to get the list of rpms to fill the file.

shivaa 05-02-2013 12:23 PM


Originally Posted by Frankly3D (Post 4943487)
Rpms="$(rpm -qa --queryformat '%10{NAME}' \n) >> "

Make this part as:

Rpms=$(rpm -qa --queryformat '%10{NAME}' \n)"

Then if you want re-direct the output of Rpms variable, then do as:

echo $Rpms >> /path/to/output_file

All times are GMT -5. The time now is 10:37 AM.