Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I am using CentOs 6.4 and I need some help setting up a script.
Here is what I am looking to automate and below is a sample of the script I setup.
1) looking to pipe the output of the data to a variable file each time the script is run. For example currently I have to run ./erase.sh >> SNxxxxxxx.txt. However optimally I would like to run just ./erase.sh and have the script file look at the output from the script and grab the SNxxxxxxx and time stamp the output file automatically.
2)Can a run a script inside a script? I think I can but just making sure.
3)Is there a way to output to screen and pipe the information at the same not. Not a big deal just wondering.
Here is the sample script<erase.sh> ddcli is a command for the card.
#!/bin/bash
# rsync using variables
SOURCEDIR=/home/user/Desktop/
./ddcli -c 4 -list
echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=Initial LIST complete=-=-=-=-=-=-=-=-=-=-=-=-=-="
./ddcli -c 4 -health
echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=Initial HEALTH complete=-=-=-=-=-=-=-=-=-=-=-=-=-="
I am using CentOs 6.4 and I need some help setting up a script.
Here is what I am looking to automate and below is a sample of the script I setup.
1) looking to pipe the output of the data to a variable file each time the script is run. For example currently I have to run ./erase.sh >> SNxxxxxxx.txt. However optimally I would like to run just ./erase.sh and have the script file look at the output from the script and grab the SNxxxxxxx and time stamp the output file automatically.
Quote:
Originally Posted by powerplyer
2)Can a run a script inside a script? I think I can but just making sure.
yes
Quote:
Originally Posted by powerplyer
3)Is there a way to output to screen and pipe the information at the same not. Not a big deal just wondering.
yes, there is a utility called tee, which does just this
Code:
echo "send to tee" | tee Log.log
cat Log.log
echo "send another to tee" | tee Log.log
cat Log.log
echo "send to tee" | tee -a Log.log
cat Log.log
echo "send another to tee" | tee -a Log.log
cat Log.log
notice what the -a did,
not much to read, but read anyway
Code:
man tee
Quote:
Originally Posted by powerplyer
Here is the sample script<erase.sh> ddcli is a command for the card.
Code:
#!/bin/bash
# rsync using variables
SOURCEDIR=/home/user/Desktop/
./ddcli -c 4 -list
echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=Initial LIST complete=-=-=-=-=-=-=-=-=-=-=-=-=-="
./ddcli -c 4 -health
echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=Initial HEALTH complete=-=-=-=-=-=-=-=-=-=-=-=-=-="
./ddcli -c 4 -format -eraseflash -s
echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=FORMAT SECUREERASE complete=-=-=-=-=-=-=-=-=-=-=-=-=-="
./ddcli -c 4 -list
echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=Final LIST complete=-=-=-=-=-=-=-=-=-=-=-=-=-="
./ddcli -c 4 -health
echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=Final HEALTH complete=-=-=-=-=-=-=-=-=-=-=-=-=-="
essentially this is a command to pull data from storage card I have.
Thank you in advance for the help.
please use code tags,, example
[code]
Your code here
[/code]
not much for me to say about that script
only that you might want to make it 'position independent'
that is, hardcode it to the location of ddcli
one way is to cd into the dir that contains ddcli
another is to use the full path, that assumes the ddcli script/program is hardcoded with relevant paths
also it will 'carry on regardless' of any failure, since I can't see ddcli, I don't know if you can make it 'smarter'
assuming ddcli uses exit codes ( with 0 meaning success and none-zero being failure )
em="=-=-=-=-=-=-=-=-=-=-=-=-=-=" # makes life easier later
# feel free to make it longer
# EqualMinus="=-=-=-=-=-=-=-=-=-=-=-=-=-="
# if you use something like vim, then there is a nice feature
# example , note <ctrl+p> is the ctrl key + p :)
# echo "${E<ctrl+p>
# it will either 'complete' the keyword, or present a list ;)
#
./ddcli -c 4 -list
if [[ "$?" == "0" ]]; then
echo "${em}Initial LIST complete${em}"
else
echo "${em} some error msg ${em}"
exit 1
fi
Hi Firerat thank you for the quick reply. Sorry about not putting the code in a box...
I am still unclear about item 1. I think I get the jist of item 3. Again, sorry some of what you said is still above my head.
Code:
#!/bin/bash
# rsync using variables
SOURCEDIR=/home/user/Desktop/
./ddcli -c 4 -list
echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=Initial LIST complete=-=-=-=-=-=-=-=-=-=-=-=-=-="
./ddcli -c 4 -health
echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=Initial HEALTH complete=-=-=-=-=-=-=-=-=-=-=-=-=-="
./ddcli -c 4 -format -eraseflash -s
echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=FORMAT SECUREERASE complete=-=-=-=-=-=-=-=-=-=-=-=-=-="
./ddcli -c 4 -list
echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=Final LIST complete=-=-=-=-=-=-=-=-=-=-=-=-=-="
./ddcli -c 4 -health
echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=Final HEALTH complete=-=-=-=-=-=-=-=-=-=-=-=-=-="
Here is a sample output from the file. Sorry if I was unclear but this is what I am trying accomplish
-- run all 5 commands (via the script) automatically output to a file called temp_output.txt
-- read the output and automatically get the serial number from the temp_output.txt
-- automatically rename the file temp_output to SN_SP24447758_<time stamp>.txt
I think my biggest question is how to automatically rename temp_output.txt to SN_SPxxxxxxxx_<timestamp>.txt. The problem is I do not know what to put in a script to read the file, get the board tracer number, rename that file with board tracer number and time stamp to a text file.
Here is a sample of the output from ddcli
Code:
WarpDrive Selected is NWD-RLP4-1860
------------------------------------------------------------------------
WarpDrive Information
------------------------------------------------------------------------
WarpDrive ID : 3
PCI Address : 00:81:00:00
PCI Slot Number : 0x05
PCIe Link Width : X8 Lane(s)
PCIe Link Rate : 0x01 (5.0 Gbps)
PCI DeviceId : 0x7E
PCI SubSystem DeviceId : 0x507
PCI SubSystem VendorId : 0x1000
SAS Address : 500605B 00568B0A0
Package Version : 10.110.04.00
Firmware Version : 110.00.01.00
Legacy BIOS Version : 110.00.00.00
UEFI BSD Version : 07.18.05.03
Chip Name : Nytro WarpDrive
Board Name : NWD-RLP4-1860
Board Assembly Number : L3-25586-00A
Board Tracer Number : SP24447758
RAID Support : YES
If you have any more insight that would be great. Please consider me a 2 year old when it comes to Linux.
Thanks again for your help
Last edited by powerplyer; 10-26-2013 at 08:58 PM.
Warning:
I have made no effort to use correct paths
I don't know if "Board Tracer Number" will appear more than once
( actually, just added the ;exit to the awk, so after first result it exits )
I get a SN_2013-10-260193116.txt (great) file but it is blank, also the filename did not pick up the board tracer number. Could it be because we are not piping the output to any file. I see the output on the screen. I grabbed all the output and attached the text file.
I made a minor modification to the script to comment out the eraseflash option. Just to test it out... The eraseflash option takes too long. I think we are almost there...
well, if those ./ddcli commands do not print to stdout, then tee will not be able to append them
I'm blind as I can't see what ddcli does
basically ddcli is a utility to pull information from the card.
If I were to run ddcli -c 1 -list in terminal --> the utility selects the card 1 and displays the list (informational) output of the card (ie FW,and other device information)to the terminal window. If I want to save it to a file I would do a ddcli -c 1 -list >> list_output.txt, as an example. Like doing ls command it would output to termianl windows and if I did a ls >> dir.txt it would output the directory content to a file called dir.txt. BTW I under stand that doing a ">>" will continue to append to that one file.
Quote:
if you see the relevant text 'fly by' when running the script it could that it is sending it to stderr
I do see the revelent information fly by
Quote:
change LogIt="|tee -a $MyTemp" to
Code:
LogIt=" 2>&1 | tee -a $MyTemp"
that redirects stderr to stdout
tee should then be appending it to the tmpfile
Is there something information I can get to help further, please let me know?
Thank you
I modified the code slightly, I pointed to the $MyTemp. The output file is correct. The only problem is the output does not "fly by" on the screen. I can only see my echo commands.
./1C_Securerase.sh
=-=-=-=-=-=-=-=-=-=-=-=-=-=Initial LIST complete=-=-=-=-=-=-=-=-=-=-=-=-=-=
=-=-=-=-=-=-=-=-=-=-=-=-=-=Initial HEALTH complete=-=-=-=-=-=-=-=-=-=-=-=-=-=
=-=-=-=-=-=-=-=-=-=-=-=-=-=Final LIST complete=-=-=-=-=-=-=-=-=-=-=-=-=-=
=-=-=-=-=-=-=-=-=-=-=-=-=-=Final HEALTH complete=-=-=-=-=-=-=-=-=-=-=-=-=-=
and here is the output of the file name and it has data.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.