Bash script, not including variable which is not empty but in output it is empty
Clash 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
linux bash backup
 |Â
show 5 more comments
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
linux bash backup
When you run the script, the stringMikrotik
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 variabledevices
. There is a filedevices
and a variabledevice
. If the filedevices
contains onlyMikroTik
, what do you expectawk ' 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 filedevices
. If the second line contains the hostname (and nothing else), you can usetail -1
to output only the last line.
â user4556274
Dec 6 '17 at 14:58
 |Â
show 5 more comments
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
linux bash backup
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
linux bash backup
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 stringMikrotik
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 variabledevices
. There is a filedevices
and a variabledevice
. If the filedevices
contains onlyMikroTik
, what do you expectawk ' 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 filedevices
. If the second line contains the hostname (and nothing else), you can usetail -1
to output only the last line.
â user4556274
Dec 6 '17 at 14:58
 |Â
show 5 more comments
When you run the script, the stringMikrotik
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 variabledevices
. There is a filedevices
and a variabledevice
. If the filedevices
contains onlyMikroTik
, what do you expectawk ' 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 filedevices
. If the second line contains the hostname (and nothing else), you can usetail -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
 |Â
show 5 more comments
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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 filedevices
and a variabledevice
. If the filedevices
contains onlyMikroTik
, what do you expectawk ' 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 filedevices
. If the second line contains the hostname (and nothing else), you can usetail -1
to output only the last line.â user4556274
Dec 6 '17 at 14:58