How run a batch file

Questions about applications and software
Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Locked
User avatar
Pepper-Mint-Patty
Level 5
Level 5
Posts: 966
Joined: Fri Dec 20, 2019 4:54 pm
Location: Royston Vasey

How run a batch file

Post by Pepper-Mint-Patty »

I need to run a batch file for Sony Dump Tool. These files are in the Sony Dump Tool folder /home/mint/Desktop/Xperia-stock-rom/sony_dump

Code: Select all

/sony_dump$ ls
sony_dump.arm32      sony_dump.i386-apple-darwin11
sony_dump.arm32_pie  sony_dump.mips32
sony_dump.arm64      sony_dump.mips64
sony_dump.arm64_pie  sony_dump.x86_64
sony_dump.exe        sony_dump.x86_64-apple-darwin11
sony_dump.i386
The folder G8441_T-Mobile-etc contains: boot + partition + many *.sin files etc.

I've tried to make a bash according to:
https://forum.xda-developers.com/t/tool ... e.3530077/

Code: Select all

#!/bin/bash
echo sony_dump test-2 /home/mint/Desktop/Xperia-stock-rom/G8441_T-Mobile-etc/
sony_dump out kernel.elf
sony_dump out boot.img
sony_dump out kernel.sin
sony_dump out /dev/block/platform/msm_sdcc.1/by-name/boot (android version only)
sony_dump out /dev/block/platform/msm_sdcc.1/by-name/FOTAKernel (android version only)
sony_dump out anysinfile.sin
Obviously it doesn't work.

Code: Select all

$ ./sony-dump-test2.sh
sony_dump test-2 /home/mint/Desktop/Xperia-stock-rom/G8441_T-Mobile-etc/
./sony-dump-test2.sh: line 3: sony_dump: command not found
./sony-dump-test2.sh: line 4: sony_dump: command not found
./sony-dump-test2.sh: line 5: sony_dump: command not found
./sony-dump-test2.sh: line 6: syntax error near unexpected token `('
./sony-dump-test2.sh: line 6: `sony_dump out /dev/block/platform/msm_sdcc.1/by-name/boot (android version only)'
How should it be done?
Either batch file or through the command line
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
If guns don't kill, then OxyContin doesn't either, heroin isn't addicitve and fairy tales are real.
19.2 Cinn, Nemo
vanadium
Level 4
Level 4
Posts: 325
Joined: Sun Dec 27, 2015 1:07 pm

Re: How run a batch file

Post by vanadium »

Commands on the terminal or in a bash script need be findable. Only executable files that reside in a few directories included in your search PATH will be found if you just provide the name of the executable. Else, you need to provide the full file path to the executable.

You can see the list of folders that are being searched for executables by typing "echo $PATH" or "printenv PATH".

The executables you call in your script are not in the path and should not be in the path. That means that you will need to proceed one of two ways:

Either
  • you first make the directory where the files reside the current one with a "cd" command
Or
  • you provide the full path to the executable. Be carefull with the latter. Sometimes, an executable needs to be run from within a specific directory to work.
So in your case, I would change the script as:

Code: Select all

#!/bin/bash
echo sony_dump test-2 /home/mint/Desktop/Xperia-stock-rom/G8441_T-Mobile-etc/
cd  /home/mint/Desktop/Xperia-stock-rom/sony_dump
./sony_dump out kernel.elf
./sony_dump out boot.img
./sony_dump out kernel.sin
./sony_dump out /dev/block/platform/msm_sdcc.1/by-name/boot (android version only)
./sony_dump out /dev/block/platform/msm_sdcc.1/by-name/FOTAKernel (android version only)
./sony_dump out anysinfile.sin
Note that you first "cd" into the directory where the executable live. Next, you precede each name of the executable with the path designator "./", which means "current directory". You need to provide that. Else, bash will search only the folders in your PATH for a matching executable. It will not search the current folder (unlike MS Windows. This is an example of one of its design aspects that is inherently less secure).
rene
Level 20
Level 20
Posts: 12240
Joined: Sun Mar 27, 2016 6:58 pm

Re: How run a batch file

Post by rene »

Poster will also want to use ./sony-dump.x86_64 rather than ./sony-dump (or rename sony_dump.x86_64 to sony-dump first) and will want to skip the two lines ending with "(android version only)" since it seems those would be applicable to the, well, android version only.
User avatar
Pepper-Mint-Patty
Level 5
Level 5
Posts: 966
Joined: Fri Dec 20, 2019 4:54 pm
Location: Royston Vasey

Re: How run a batch file

Post by Pepper-Mint-Patty »

I am trying to restore the stock rom to a smartphone. This program should make a FTF from the dl stock rom files. So i guess 'android version only' is pretty important.

I changed the file as i understood the instructions

Code: Select all

$ ./sony-dump-test2.sh
#!/bin/bash
echo sony_dump test-2 /home/mint/Desktop/Xperia-stock-rom/G8441_T-Mobile-etc/
cd  /home/mint/Desktop/Xperia-stock-rom/sony_dump
./sony-dump.x86_64_dump out kernel.elf
./sony-dump.x86_64_dump out boot.img
./sony-dump.x86_64_dump out kernel.sin
./sony-dump.x86_64_dump out /dev/block/platform/msm_sdcc.1/by-name/boot (android version only)
./sony-dump.x86_64_dump out /dev/block/platform/msm_sdcc.1/by-name/FOTAKernel (android version only)
./sony-dump.x86_64_dump out anysinfile.sin
The folder Xperia-stock-rom contains: sony_dump + test-2+ G8441_T-Mobile-etc + sony-dump-test2.sh
The folder G8441_T-Mobile-etc contains: boot + partition + many *.sin files etc.
I've put the sony-dump-test2.sh file in any of the 3 folders within Xperia-stock-rom.
Outcome is always:

Code: Select all

$ sony-dump-test2.sh
sony-dump-test2.sh: command not found
If guns don't kill, then OxyContin doesn't either, heroin isn't addicitve and fairy tales are real.
19.2 Cinn, Nemo
User avatar
shedyed
Level 4
Level 4
Posts: 298
Joined: Wed Feb 03, 2021 5:12 pm

Re: How run a batch file

Post by shedyed »

I suggest you re-read vanadium's reply and understand the PATH concept to move forward
User avatar
Flemur
Level 20
Level 20
Posts: 10097
Joined: Mon Aug 20, 2012 9:41 pm
Location: Potemkin Village

Re: How run a batch file

Post by Flemur »

Pepper-Mint-Patty wrote: Sun Sep 26, 2021 10:04 am Outcome is always:

Code: Select all

$ sony-dump-test2.sh
sony-dump-test2.sh: command not found
Next, you precede each name of the executable with the path designator "./", which means "current directory". You need to provide that. Else, bash will search only the folders in your PATH for a matching executable.
IOW, do this
./sony-dump-test2.sh
or this
sh sony-dump-test2.sh
Please edit your original post title to include [SOLVED] if/when it is solved!
Your data and OS are backed up....right?
User avatar
Pepper-Mint-Patty
Level 5
Level 5
Posts: 966
Joined: Fri Dec 20, 2019 4:54 pm
Location: Royston Vasey

Re: How run a batch file

Post by Pepper-Mint-Patty »

it makes no difference: ./sony-dump-test2.sh or sh sony-dump-test2.sh Nore having the file within sony_dump folder or a folder 1 level higher.
outcome always:

Code: Select all

$ sony-dump-test2.sh  sony-dump-test2.sh: command not found
Should't the program sony_dump.x86_64 be activated before somehow?
If guns don't kill, then OxyContin doesn't either, heroin isn't addicitve and fairy tales are real.
19.2 Cinn, Nemo
1000
Level 6
Level 6
Posts: 1028
Joined: Wed Jul 29, 2020 2:14 am

Re: How run a batch file

Post by 1000 »

Pepper-Mint-Patty on YouTube you have tutorials how use terminal / how build /run scripts.

Edit
For exmaple
https://www.youtube.com/watch?v=s3ii48qYBxA
User avatar
Flemur
Level 20
Level 20
Posts: 10097
Joined: Mon Aug 20, 2012 9:41 pm
Location: Potemkin Village

Re: How run a batch file

Post by Flemur »

Pepper-Mint-Patty wrote: Mon Sep 27, 2021 5:55 am it makes no difference: ./sony-dump-test2.sh or sh sony-dump-test2.sh Nore having the file within sony_dump folder or a folder 1 level higher.
outcome always:

Code: Select all

$ sony-dump-test2.sh  sony-dump-test2.sh: command not found
Should't the program sony_dump.x86_64 be activated before somehow?
Then the file sony-dump-test2.sh isn't in your current directory; the sh command should actually return:

Code: Select all

$ sh dfksdjfs
sh: dfksdjfs: No such file or directory
not "command not found".

Check:

Code: Select all

ls sony-dump-test2.sh
Find it:

Code: Select all

sudo find / -iname sony-dump-test2.sh
Edit: In your first post sony-dump-test2.sh was found and it started but it couldn't find the sony_dump script:

You wrote:
Obviously it doesn't work.

Code: Select all

$ ./sony-dump-test2.sh
sony_dump test-2 /home/mint/Desktop/Xperia-stock-rom/G8441_T-Mobile-etc/
./sony-dump-test2.sh: line 3: sony_dump: command not found 
Please edit your original post title to include [SOLVED] if/when it is solved!
Your data and OS are backed up....right?
Locked

Return to “Software & Applications”