Bash script, not including variable which is not empty but in output it is empty

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












I have a problem with bash script. I am backing up the devices. I wrote simple bash script, which will download files. Indeed, wildcard is not working so I am doing that manual way. When I variable device, it is not included in filelog, filebackup or fileexport variable. Can you help me please? I am including code.



 #!/bin/bash
user="admin"
address="IP"
#command will get devcie hostname in complex form
ssh $user@$address '/system identity print interval=' > devices

#will get device hostname
tmpDevices=$(cat devices)
device=$(echo $tmpDevices | awk ' print $2 ')
echo "Device hostname is $device"

#custom months names
day=$(date +%d)
mon=$(date +%m)
if [ $mon == 12 ]
then
mon="dec"
elif [ $mon == 1 ]
then
mon="jan"
elif [ $mon == 2 ]
then
mon="feb"
elif [ $mon == 3 ]
then
mon="mar"
elif [ $mon == 4 ]
then
mon="apr"
elif [ $mon == 5 ]
then
mon="may"
elif [ $mon == 6 ]
then
mon="jun"
elif [ $mon == 7 ]
then
mon="jul"
elif [ $mon == 8 ]
then
mon="aug"
elif [ $mon == 9 ]
then
mon="sep"
elif [ $mon == 10 ]
then
mon="oct"
elif [ $mon == 11 ]
then
mon="nov"
fi



#Creation of backup, log export, export file
#echo "Creating backup file"
#ssh $user@$address ':local name [/system identity get name];:local date [/system clock get date];:local day [ :pick $date 4 6 ];:local month [ :pick $date 0 3 ];:local backupName ($name."_".$month.$day."backup");:put $backupName;/system backup save name=$backupName'
#echo "exporting config"
#ssh $user@$address ':local name [/system identity get name];:local date [/system clock get date];:local day [ :pick $date 4 6 ];:local month [ :pick $date 0 3 ];:local backupName ($name."_".$month.$day."export");:put $backupName;/export file=$backupName'
#echo "exporting log"
#ssh $user@$address ':local name [/system identity get name];:local date [/system clock get date];:local day [ :pick $date 4 6 ];:local month [ :pick $date 0 3 ];:local backupName ($name."_".$month.$day."log");:put $backupName;/log print file=$backupName'

#editing month format
filelog="$device_$mon$daylog.txt"
filebackup="$device_$mon$daybackup.backup"
fileexport="$device_$mon$dayexport.rsc"
echo $device
echo $filelog
echo $filebackup
echo $fileexport


When I run the script, it will shows me devices as Mikrotik, but is not included in variable. The output is _dec06log.txt etc.



Thank you.
Adrian







share|improve this question






















  • When you run the script, the string Mikrotik shows up to your screen, but does not end up in the device variable & filename?
    – Jeff Schaller
    Dec 6 '17 at 13:54










  • yes, variable devices output is MikroTik but is not in use in filelog, filebackup, and fileexport variables included
    – Adrian Bardossy
    Dec 6 '17 at 14:30






  • 1




    There is no variable devices. There is a file devices and a variable device. If the file devices contains only MikroTik, what do you expect awk ' print $2 ' to produce?
    – Philippos
    Dec 6 '17 at 14:34










  • with awk I have reduced 2 lines of text file to one to filter just hostname
    – Adrian Bardossy
    Dec 6 '17 at 14:53










  • @AdrianBardossy, awk 'print $2' does not reduce two lines of text to one. Please edit your question to include the full content of the file devices. If the second line contains the hostname (and nothing else), you can use tail -1 to output only the last line.
    – user4556274
    Dec 6 '17 at 14:58















up vote
0
down vote

favorite












I have a problem with bash script. I am backing up the devices. I wrote simple bash script, which will download files. Indeed, wildcard is not working so I am doing that manual way. When I variable device, it is not included in filelog, filebackup or fileexport variable. Can you help me please? I am including code.



 #!/bin/bash
user="admin"
address="IP"
#command will get devcie hostname in complex form
ssh $user@$address '/system identity print interval=' > devices

#will get device hostname
tmpDevices=$(cat devices)
device=$(echo $tmpDevices | awk ' print $2 ')
echo "Device hostname is $device"

#custom months names
day=$(date +%d)
mon=$(date +%m)
if [ $mon == 12 ]
then
mon="dec"
elif [ $mon == 1 ]
then
mon="jan"
elif [ $mon == 2 ]
then
mon="feb"
elif [ $mon == 3 ]
then
mon="mar"
elif [ $mon == 4 ]
then
mon="apr"
elif [ $mon == 5 ]
then
mon="may"
elif [ $mon == 6 ]
then
mon="jun"
elif [ $mon == 7 ]
then
mon="jul"
elif [ $mon == 8 ]
then
mon="aug"
elif [ $mon == 9 ]
then
mon="sep"
elif [ $mon == 10 ]
then
mon="oct"
elif [ $mon == 11 ]
then
mon="nov"
fi



#Creation of backup, log export, export file
#echo "Creating backup file"
#ssh $user@$address ':local name [/system identity get name];:local date [/system clock get date];:local day [ :pick $date 4 6 ];:local month [ :pick $date 0 3 ];:local backupName ($name."_".$month.$day."backup");:put $backupName;/system backup save name=$backupName'
#echo "exporting config"
#ssh $user@$address ':local name [/system identity get name];:local date [/system clock get date];:local day [ :pick $date 4 6 ];:local month [ :pick $date 0 3 ];:local backupName ($name."_".$month.$day."export");:put $backupName;/export file=$backupName'
#echo "exporting log"
#ssh $user@$address ':local name [/system identity get name];:local date [/system clock get date];:local day [ :pick $date 4 6 ];:local month [ :pick $date 0 3 ];:local backupName ($name."_".$month.$day."log");:put $backupName;/log print file=$backupName'

#editing month format
filelog="$device_$mon$daylog.txt"
filebackup="$device_$mon$daybackup.backup"
fileexport="$device_$mon$dayexport.rsc"
echo $device
echo $filelog
echo $filebackup
echo $fileexport


When I run the script, it will shows me devices as Mikrotik, but is not included in variable. The output is _dec06log.txt etc.



Thank you.
Adrian







share|improve this question






















  • When you run the script, the string Mikrotik shows up to your screen, but does not end up in the device variable & filename?
    – Jeff Schaller
    Dec 6 '17 at 13:54










  • yes, variable devices output is MikroTik but is not in use in filelog, filebackup, and fileexport variables included
    – Adrian Bardossy
    Dec 6 '17 at 14:30






  • 1




    There is no variable devices. There is a file devices and a variable device. If the file devices contains only MikroTik, what do you expect awk ' print $2 ' to produce?
    – Philippos
    Dec 6 '17 at 14:34










  • with awk I have reduced 2 lines of text file to one to filter just hostname
    – Adrian Bardossy
    Dec 6 '17 at 14:53










  • @AdrianBardossy, awk 'print $2' does not reduce two lines of text to one. Please edit your question to include the full content of the file devices. If the second line contains the hostname (and nothing else), you can use tail -1 to output only the last line.
    – user4556274
    Dec 6 '17 at 14:58













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I have a problem with bash script. I am backing up the devices. I wrote simple bash script, which will download files. Indeed, wildcard is not working so I am doing that manual way. When I variable device, it is not included in filelog, filebackup or fileexport variable. Can you help me please? I am including code.



 #!/bin/bash
user="admin"
address="IP"
#command will get devcie hostname in complex form
ssh $user@$address '/system identity print interval=' > devices

#will get device hostname
tmpDevices=$(cat devices)
device=$(echo $tmpDevices | awk ' print $2 ')
echo "Device hostname is $device"

#custom months names
day=$(date +%d)
mon=$(date +%m)
if [ $mon == 12 ]
then
mon="dec"
elif [ $mon == 1 ]
then
mon="jan"
elif [ $mon == 2 ]
then
mon="feb"
elif [ $mon == 3 ]
then
mon="mar"
elif [ $mon == 4 ]
then
mon="apr"
elif [ $mon == 5 ]
then
mon="may"
elif [ $mon == 6 ]
then
mon="jun"
elif [ $mon == 7 ]
then
mon="jul"
elif [ $mon == 8 ]
then
mon="aug"
elif [ $mon == 9 ]
then
mon="sep"
elif [ $mon == 10 ]
then
mon="oct"
elif [ $mon == 11 ]
then
mon="nov"
fi



#Creation of backup, log export, export file
#echo "Creating backup file"
#ssh $user@$address ':local name [/system identity get name];:local date [/system clock get date];:local day [ :pick $date 4 6 ];:local month [ :pick $date 0 3 ];:local backupName ($name."_".$month.$day."backup");:put $backupName;/system backup save name=$backupName'
#echo "exporting config"
#ssh $user@$address ':local name [/system identity get name];:local date [/system clock get date];:local day [ :pick $date 4 6 ];:local month [ :pick $date 0 3 ];:local backupName ($name."_".$month.$day."export");:put $backupName;/export file=$backupName'
#echo "exporting log"
#ssh $user@$address ':local name [/system identity get name];:local date [/system clock get date];:local day [ :pick $date 4 6 ];:local month [ :pick $date 0 3 ];:local backupName ($name."_".$month.$day."log");:put $backupName;/log print file=$backupName'

#editing month format
filelog="$device_$mon$daylog.txt"
filebackup="$device_$mon$daybackup.backup"
fileexport="$device_$mon$dayexport.rsc"
echo $device
echo $filelog
echo $filebackup
echo $fileexport


When I run the script, it will shows me devices as Mikrotik, but is not included in variable. The output is _dec06log.txt etc.



Thank you.
Adrian







share|improve this question














I have a problem with bash script. I am backing up the devices. I wrote simple bash script, which will download files. Indeed, wildcard is not working so I am doing that manual way. When I variable device, it is not included in filelog, filebackup or fileexport variable. Can you help me please? I am including code.



 #!/bin/bash
user="admin"
address="IP"
#command will get devcie hostname in complex form
ssh $user@$address '/system identity print interval=' > devices

#will get device hostname
tmpDevices=$(cat devices)
device=$(echo $tmpDevices | awk ' print $2 ')
echo "Device hostname is $device"

#custom months names
day=$(date +%d)
mon=$(date +%m)
if [ $mon == 12 ]
then
mon="dec"
elif [ $mon == 1 ]
then
mon="jan"
elif [ $mon == 2 ]
then
mon="feb"
elif [ $mon == 3 ]
then
mon="mar"
elif [ $mon == 4 ]
then
mon="apr"
elif [ $mon == 5 ]
then
mon="may"
elif [ $mon == 6 ]
then
mon="jun"
elif [ $mon == 7 ]
then
mon="jul"
elif [ $mon == 8 ]
then
mon="aug"
elif [ $mon == 9 ]
then
mon="sep"
elif [ $mon == 10 ]
then
mon="oct"
elif [ $mon == 11 ]
then
mon="nov"
fi



#Creation of backup, log export, export file
#echo "Creating backup file"
#ssh $user@$address ':local name [/system identity get name];:local date [/system clock get date];:local day [ :pick $date 4 6 ];:local month [ :pick $date 0 3 ];:local backupName ($name."_".$month.$day."backup");:put $backupName;/system backup save name=$backupName'
#echo "exporting config"
#ssh $user@$address ':local name [/system identity get name];:local date [/system clock get date];:local day [ :pick $date 4 6 ];:local month [ :pick $date 0 3 ];:local backupName ($name."_".$month.$day."export");:put $backupName;/export file=$backupName'
#echo "exporting log"
#ssh $user@$address ':local name [/system identity get name];:local date [/system clock get date];:local day [ :pick $date 4 6 ];:local month [ :pick $date 0 3 ];:local backupName ($name."_".$month.$day."log");:put $backupName;/log print file=$backupName'

#editing month format
filelog="$device_$mon$daylog.txt"
filebackup="$device_$mon$daybackup.backup"
fileexport="$device_$mon$dayexport.rsc"
echo $device
echo $filelog
echo $filebackup
echo $fileexport


When I run the script, it will shows me devices as Mikrotik, but is not included in variable. The output is _dec06log.txt etc.



Thank you.
Adrian









share|improve this question













share|improve this question




share|improve this question








edited Aug 25 at 22:24









Rui F Ribeiro

35.6k1271114




35.6k1271114










asked Dec 6 '17 at 13:36









Adrian Bardossy

23




23











  • When you run the script, the string Mikrotik shows up to your screen, but does not end up in the device variable & filename?
    – Jeff Schaller
    Dec 6 '17 at 13:54










  • yes, variable devices output is MikroTik but is not in use in filelog, filebackup, and fileexport variables included
    – Adrian Bardossy
    Dec 6 '17 at 14:30






  • 1




    There is no variable devices. There is a file devices and a variable device. If the file devices contains only MikroTik, what do you expect awk ' print $2 ' to produce?
    – Philippos
    Dec 6 '17 at 14:34










  • with awk I have reduced 2 lines of text file to one to filter just hostname
    – Adrian Bardossy
    Dec 6 '17 at 14:53










  • @AdrianBardossy, awk 'print $2' does not reduce two lines of text to one. Please edit your question to include the full content of the file devices. If the second line contains the hostname (and nothing else), you can use tail -1 to output only the last line.
    – user4556274
    Dec 6 '17 at 14:58

















  • When you run the script, the string Mikrotik shows up to your screen, but does not end up in the device variable & filename?
    – Jeff Schaller
    Dec 6 '17 at 13:54










  • yes, variable devices output is MikroTik but is not in use in filelog, filebackup, and fileexport variables included
    – Adrian Bardossy
    Dec 6 '17 at 14:30






  • 1




    There is no variable devices. There is a file devices and a variable device. If the file devices contains only MikroTik, what do you expect awk ' print $2 ' to produce?
    – Philippos
    Dec 6 '17 at 14:34










  • with awk I have reduced 2 lines of text file to one to filter just hostname
    – Adrian Bardossy
    Dec 6 '17 at 14:53










  • @AdrianBardossy, awk 'print $2' does not reduce two lines of text to one. Please edit your question to include the full content of the file devices. If the second line contains the hostname (and nothing else), you can use tail -1 to output only the last line.
    – user4556274
    Dec 6 '17 at 14:58
















When you run the script, the string Mikrotik shows up to your screen, but does not end up in the device variable & filename?
– Jeff Schaller
Dec 6 '17 at 13:54




When you run the script, the string Mikrotik shows up to your screen, but does not end up in the device variable & filename?
– Jeff Schaller
Dec 6 '17 at 13:54












yes, variable devices output is MikroTik but is not in use in filelog, filebackup, and fileexport variables included
– Adrian Bardossy
Dec 6 '17 at 14:30




yes, variable devices output is MikroTik but is not in use in filelog, filebackup, and fileexport variables included
– Adrian Bardossy
Dec 6 '17 at 14:30




1




1




There is no variable devices. There is a file devices and a variable device. If the file devices contains only MikroTik, what do you expect awk ' print $2 ' to produce?
– Philippos
Dec 6 '17 at 14:34




There is no variable devices. There is a file devices and a variable device. If the file devices contains only MikroTik, what do you expect awk ' print $2 ' to produce?
– Philippos
Dec 6 '17 at 14:34












with awk I have reduced 2 lines of text file to one to filter just hostname
– Adrian Bardossy
Dec 6 '17 at 14:53




with awk I have reduced 2 lines of text file to one to filter just hostname
– Adrian Bardossy
Dec 6 '17 at 14:53












@AdrianBardossy, awk 'print $2' does not reduce two lines of text to one. Please edit your question to include the full content of the file devices. If the second line contains the hostname (and nothing else), you can use tail -1 to output only the last line.
– user4556274
Dec 6 '17 at 14:58





@AdrianBardossy, awk 'print $2' does not reduce two lines of text to one. Please edit your question to include the full content of the file devices. If the second line contains the hostname (and nothing else), you can use tail -1 to output only the last line.
– user4556274
Dec 6 '17 at 14:58
















active

oldest

votes











Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f409215%2fbash-script-not-including-variable-which-is-not-empty-but-in-output-it-is-empty%23new-answer', 'question_page');

);

Post as a guest



































active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f409215%2fbash-script-not-including-variable-which-is-not-empty-but-in-output-it-is-empty%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

How to check contact read email or not when send email to Individual?

Displaying single band from multi-band raster using QGIS

How many registers does an x86_64 CPU actually have?