*.bat file under Linux

Solved
kaham Posted messages 174 Registration date   Status Member Last intervention   -  
dindoun Posted messages 1047 Status Member -
Hello,

I've been writing Batch scripts on Windows for a while and I want to do the same on Linux. Let me explain:

On Windows, I create *.bat files that are interpreted by the console. I would like to create a file interpreted by the Linux console that has an icon on my desktop (Linux) and I just have to click on it to "execute" it (or launch it from the console).

On Windows, it's very simple: you open a text editor, write your script, and save it as a *.bat file.
But I have no idea how to do this on Linux.
Configuration: Windows XP Firefox 3.0.3

21 answers

  • 1
  • 2
Youplaboum
 
./test.bat
4
kaham Posted messages 174 Registration date   Status Member Last intervention   5
 
Apparemment, j'ai un problème avec le "shebang" ! car il me met comme message d'erreur :
-bash: ./test.bat: bin/sh: bad interpreter: No such file or directory
Pourtant, j'ai bien mis en en-tête de fichier :
#!bin/sh -x
2
eZula Posted messages 3509 Status Contributor 392
 
#!/bin/sh -x
2
TY
 
It's all good, I've solved the problem, thanks anyway. :)
2
Youplaboum
 
il te manque un /

#!/bin/sh
1
kaham Posted messages 174 Registration date   Status Member Last intervention   5
 
It was indeed that! :s just simple basic mistakes.

However, a new error message:
-bash: ./test.bat: Permission denied
??? Yet I am indeed under root ???
1
Youplaboum
 
steps,

id

and,

ls -l
0
jipicy Posted messages 40842 Registration date   Status Moderator Last intervention   4 898
 
Hello,

On GNU/Linux, it's very simple, you open a text editor, type your script (with a shebang at the top) and save it as a *.something file (but that's optional, you can save it as ".whatever" or even without an extension), make it executable (chmod +x the_file) and you're good to go ;-))

--
$ man woman
There is no manual page for woman.
0
kaham Posted messages 174 Registration date   Status Member Last intervention   5
 
Here are the steps you can follow to execute your program after making the file executable: ```html
Pour exécuter votre programme, vous devez utiliser la commande suivante dans votre console :
./test.bat

Assurez-vous que vous êtes dans le bon répertoire où se trouve le fichier 'test.bat'. Si ce n'est pas le cas, naviguez jusqu'au répertoire approprié avec la commande
cd chemin/vers/le/répertoire

où 'chemin/vers/le/répertoire' est le chemin d'accès à l'emplacement de votre fichier. Ensuite, vous pouvez exécuter le programme comme indiqué.
```
0
kaham Posted messages 174 Registration date   Status Member Last intervention   5
 

 # id uid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10(wheel),11(floppy) # ls -i 3327 Bureau/ 3328 Définir\ l'adresse\ IP 3329 scripts_exemples/ 6904 test.bat 
0
Youplaboum
 
ls -l

( ls -elleuh )
0
kaham Posted messages 174 Registration date   Status Member Last intervention   5
 
Console :

# id
uid=0(root) gid=0(root) groupes=0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10(wheel),11(floppy)
# ls -l
total 5
drwx---r-x 2 root root 40 Oct 16 18:08 Bureau/
-rw-r--r-- 1 root root 323 2 mai 2005 Set\ adresse\ IP
drwxr-xr-x 2 root root 182 6 mars 2007 scripts_exemples/
-rw-r--r-- 1 root root 62 Oct 16 17:57 test.bat
0
Youplaboum
 
chmod +x test.bat
0
kaham Posted messages 174 Registration date   Status Member Last intervention   5
 
No, I clearly saw that I wasn't allowed to execute the test.bat file
but chmod +x doesn't change the access rights and that really is a problem :s

yet I am indeed in SuperUser (root) and I can't change the file access rights.

could it be because I'm using VirtualBox to emulate Linux 2.6?
0
Youplaboum
 
Is he making a mistake?
0
dindoun Posted messages 1047 Status Member 135
 
Hi
since you're a beginner, you shouldn't run batch processes as root, you could get into serious trouble:
for example, a
rm -r / home/moi/mesfichier
would destroy your entire Linux because a space was inserted between / and home
whereas as a normal user it wouldn't work.
0
kaham Posted messages 174 Registration date   Status Member Last intervention   5
 
Yes, I know, but Linux is not installed on my machine ^^

I am just emulating it to quickly switch from WinXP to Linux, so there’s not too much risk on that side.
0
TY
 
Hello everyone

I also have a small problem with the access rights to my .bat: And this even though I gave it all the rights:
-rwxrwxrwx 1 root root 113 Feb 4 11:19 projet.bat*

However, when I run the .bat it shows me a permission error :/
bash: ./projet.bat: /lib/modules/2.6.12-12mdk/comedi/drivers: bad interpreter: Permission denied

Does anyone have a suggestion to share with me?

Thank you all. :D
0
dindoun Posted messages 1047 Status Member 135
 
hello
to be clear: what do you do to run the bat, what machine, what distribution...
0
TY
 
-Execution of the bat: ./projet.sh
-mandriva 2006.

there you go, thanks for responding ^^
0
linuxnico Posted messages 206 Status Member 10
 
At the same time, the easiest thing would be for you to send us your script directly, we could correct it more easily!
0
TY
 


#!/lib/modules/2.6.12-12mdk
depmod -a
#!/lib/modules/2.6.12-12mdk/comedi/drivers
modprobe ni_pcimio
comedi_config /dev/comedi0 ni_pcimio
exit

I'm not sure if it’s correct, but I primarily have a permission issue.
0
dindoun Posted messages 1047 Status Member 135
 
Sorry TY I haven't been here for a long time

could you tell us how you did it?
0
  • 1
  • 2