1

I'm writing a script to configure a router based on linux remotely. The first step is to obtain a serial number of the device which I want to:

  1. Create a folder of the same name as the serial number
  2. Create a text file with the serial number
  3. Put a line containing this serial number to the config file

Task 2 is the easiest - mnf_info -s > sn.txt, but how do I extract the actual name and pass it do mkdir and sed after that?

Also, do you have any clue how to change password remotely without any interaction - I do not have expect command on that device, so I have to do it otherwise. Any ideas?

Thanks in advance

Krzysztof

2
  • How do you run the script? Show your unfinished script in the question, formatted as a code block.
    – Bodo
    Commented Jan 26, 2022 at 17:07
  • Please try to stick to one problem per question. The password question is a different matter.
    – FelixJN
    Commented Jan 26, 2022 at 19:08

2 Answers 2

1

You may save the output of a command via variable=$(command). So in your case:

serial="$(mnf_info -s)"
mkdir "$serial"
echo "$serial" > "$serial"/sn.txt

Now if you want to run that locally saved script remotely, you may save the above lines (locally) in myscript, then use

ssh [email protected] "bash" <myscript
-1
ssh $i <<'EOF'
ser=$(mnf_info -s)
mkdir $ser
mnf_info -s >sn.txt
sed -i '1i $ser'  configfile
EOF

Here we saving serial number in variable and later using to creating directory and add variable content in config file

This may help you
2
  • Thanks - it worked for me perfectly.
    – Kal800
    Commented Jan 27, 2022 at 18:04
  • Can you please vote for my answer Commented Jan 27, 2022 at 18:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .