Armbian can't run script - linux

I'm not so confident with Linux but, I've installed Armbian recently, and I can't make a script to run.
I have an Orange PI zero, the script that I found did run on Ubuntu server, so I'm fairly sure that that's not the problem. I need this script for restarting the router daily.
Note: I didn't wrote the script, I copied it from a forum that I don't remember now.
#!/bin/sh
echo "Get session key..."
SKEY=curl -s http://192.168.0.1/login.asp | perl -ne 'if(/var SessionKey = (\S+);/) {print
"$1\n";}' echo "Login... ($SKEY)" curl -X POST -d "loginUsername=admin&loginPassword=<PASSWORD GOES HERE>&loginOrInitDS=0"
http://192.168.0.1/goform/login?sessionKey=$SKEY echo "Get session new key..." SKEY=curl -s
http://192.168.0.1/RgSetup.asp | perl -ne 'if(/var SessionKey = (\S+);/) {print "$1\n";}' echo "Issue reboot...
($SKEY)" curl "http://192.168.0.1/goform/RgSetup?sessionKey=$SKEY" \
-H 'Referer: http://192.168.0.1/RgSetup.asp' \
--data 'WanLeaseAction=0&ApplyRgSetupAction=0&RebootAction=1' exit 1
I removed the password for this post, but that's not the problem. Anyways.
Here's the console:
root#orangepizero:~# ./router.sh
Get session key...
./router.sh: 3: ./router.sh: -s: not found
Can't open echo: No such file or directory.
Can't open Login... (): No such file or directory.
Can't open curl: No such file or directory.
Can't open -X: No such file or directory.
Can't open POST: No such file or directory.
Can't open -d: No such file or directory.
Can't open loginUsername=admin&loginPasswosmierd=<PASSWORD GOES HERE>&loginOrInitDS=0: No such file or directory.
./router.sh: 5: ./router.sh: http://192.168.0.1/goform/login?sessionKey=: not found
./router.sh: 6: ./router.sh: http://192.168.0.1/RgSetup.asp: not found
Can't open echo: No such file or directory.
Can't open Issue reboot...
(): No such file or directory.
Can't open curl: No such file or directory.
Can't open http://192.168.0.1/goform/RgSetup?sessionKey=: No such file or directory.
Can't open -H: No such file or directory.
Can't open Referer: http://192.168.0.1/RgSetup.asp: No such file or directory.
Can't open --data: No such file or directory.
Can't open WanLeaseAction=0&ApplyRgSetupAction=0&RebootAction=1: No such file or directory.
Can't open exit: No such file or directory.
Can't open 1: No such file or directory.
root#orangepizero:~#
I've tried:
chmod +x router.sh
apt-get upgrade
reinstalling curl
I think I'm missing some component, that would explain why did this run on Ubuntu server.
Thanks in advance!

Related

How to access specific path in linux using shellscript

Let us consider an example,
scriptPath=/home/sharath/Downloads/Atollic_TrueSTUDIO_for_STM32_9.2.0_installer
In the above line of code, If user is "sharath" then he can access a file/folder same way if the user is different how can access that folder/file dynamically.
below is my shellscript(.sh file):
#!/bin/bash
set -eu
configLocation=/etc/atollic
scriptPath=/home/sharath/Downloads/Atollic_TrueSTUDIO_for_STM32_9.2.0_installer
family=STM32
arch=x86_64
version=9.2.0
configFile=${configLocation}/TrueSTUDIO_for_${family}_${arch}_${version}.properties
installPath=/opt/Atollic_TrueSTUDIO_for_${family}_${arch}_${version}/
mkdir -p /opt/Atollic_TrueSTUDIO_for_STM32_x86_64_9.2.0/
tar xzf ${scriptPath}/install.data -C /opt/Atollic_TrueSTUDIO_for_STM32_x86_64_9.2.0/
In last line of the script, ${scriptPath} is diffrent for diffrent user, how can handle in shell script.
Update 1:
if i use, ${USER} or ${HOME} or whoami which returns "root" ,
Here is my log:
tar (child): /root/Downloads/Atollic_TrueSTUDIO_for_STM32_9.2.0_installer/install.data: Cannot open: No such file or directory tar (child): Error is not recoverable: exiting now
Update 2:
Currently user in "root"
Use $HOME for the start of scriptPath, i.e:
scriptPath=${HOME}/Downloads/Atollic_TrueSTUDIO_for_STM32_9.2.0_installer
I tried with couple of way and finally i found with below solution-
Use below script for the
users
myuser=$(users)
echo "The user is " $myuser
Here users returns current user name.
Your script become:
#!/bin/bash
users
myuser=$(users)
set -eu
configLocation=/etc/atollic
scriptPath=/home/$myuser/Downloads/Atollic_TrueSTUDIO_for_STM32_9.2.0_installer
family=STM32
arch=x86_64
version=9.2.0
configFile=${configLocation}/TrueSTUDIO_for_${family}_${arch}_${version}.properties
installPath=/opt/Atollic_TrueSTUDIO_for_${family}_${arch}_${version}/
mkdir -p /opt/Atollic_TrueSTUDIO_for_STM32_x86_64_9.2.0/
tar xzf ${scriptPath}/install.data -C /opt/Atollic_TrueSTUDIO_for_STM32_x86_64_9.2.0/
Thanks for answered my question.
Dynamic_Path="/home/$(whoami)/$SCRIPT_PATH"
What is the Linux OS you are using?
You can simply use as below,
scriptPath=~/Downloads/Atollic_TrueSTUDIO_for_STM32_9.2.0_installer
where ~ refers to the home directory of the user. i.e. /home/sarath
One other way is to use it like below,
scriptPath="/home/whoami/Downloads/Atollic_TrueSTUDIO_for_STM32_9.2.0_installer"

shell script: ftp to check existing file

I've a simple shell script to transfer daily log file to another Windows FTP.
The problem is if the file is already there, it will still uploading a new one even though the file name is exactly the same.
How to perform a quick check on this script? If the file is there, then it won't proceed with FTP transfer
ftp -n -v $HOST << EOT
user $USER $PASSWD
prompt
bin
mput $FILE
bye
EOT
It is easy in Unix with ftp. First login to the system through ftp and run a ls -ltr command through ftp and list the files in a history.txt file(see below my example) and while transferring the file first check whether that file is already available in history file or not. And if available do not transfer that file. I do it like below:-
HISTORY_FILE="history.txt"
ftp -n -v $HOST << EOT
user $USER $PASSWD
prompt
bin
ls -rtE $HISTORY_FILE
bye
EOT
Now you can use below command to check:-
ISFILENAMEEXIST=$(cat $HISTORY_FILE | grep $FILE)
Now if the file exist in history.txt, do not send that file and if not available send it through ftp.

mput Not Transferring All Files During FTP Transfer

I'm having issues with my Unix FTP script...
It's only transferring the first three files in the directory that I'm local cd'ing into during the FTP session.
Here's the bash script that I'm using:
#!/bin/sh
YMD=$(date +%Y%m%d)
HOST='***'
USER='***'
PASSWD=***
FILE=*.png
RUNHR=19
ftp -inv ${HOST} <<EOF
quote USER ${USER}
quote PASS ${PASSWD}
cd /models/rtma/t2m/${YMD}/${RUNHR}/
mkdir /models/rtma/t2m/${YMD}/
mkdir /models/rtma/t2m/${YMD}/${RUNHR}/
lcd /home/aaron/grads/syndicated/rtma/t2m/${YMD}/${RUNHR}Z/
binary
prompt
mput ${FILE}
quit
EOF
exit 0
Any ideas?
I had encountered same issue, I have to transfer 400K files but mput * or mput *.pdf was not moving all files in one go
tried timeout :fails
tried -r recursive :fails
tried increasing Data/control timeout in IIS :fails
tried -i
Prompt
scripting fails
Finally went to use portable filezilla connect to from source and transferred the all files

How to downlaod a file in a directory using wget command in bash script?

I want to download a list of files using "wget" command of linux in a bash script file. The problem is that when I am trying to change the directory to another subdirectory in my home, it does not work and the wget after the cd command will download the files in my home directory not the desired subdirectory
mkdir -m 777 "dbback2012"
cd "dbback2012"
wget -r [FTP URL]
The problem is that the downloaded files via wget are in the home directory not the "dbback2012" directory.
There's nothing wrong with the code, you either
haven't shown us the real code
the script is executed somewhere else, check the working directory: pwd
the script failed to create the directory mkdir -m 777 "dbback2012" || (echo "ooops"; exit 1)

Sending file through ssh2, scp

I need to send a copy from server1 to server2 using ssh2. Both are using ubuntu, and I'm trying sending it with the scp command:
scp test.txt userName#server2_direction:/folder_destination
But I'm getting an error:
test.txt: No such file or directory
I tried putting the complete url: /users/asd/my_user/folder/test.txt, but it doesn't work either.
Any hints?
You are in the wrong directory on the source computer. Check if there is test.txt in the current directory.
$ ls -l test.txt

Resources