LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to add separate command results together to place a file in particular location. (http://www.linuxquestions.org/questions/linux-newbie-8/how-to-add-separate-command-results-together-to-place-a-file-in-particular-location-4175460403/)

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
~/$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

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

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

shivaa 05-02-2013 09:04 AM

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


Frankly3D 05-02-2013 11:22 AM

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.

shivaa 05-02-2013 12:23 PM

Quote:

Originally Posted by Frankly3D (Post 4943487)
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


All times are GMT -5. The time now is 01:23 PM.