Overclock.net › Forums › Software, Programming and Coding › Operating Systems › Linux, Unix › Help with Linux "bat file"
New Posts  All Forums:Forum Nav:

Help with Linux "bat file"

post #1 of 9
Thread Starter 
I'm currently using a linux machine running Ubuntu 10.10 to send files to a CNC machine via GtkTerm.

We're moving to a new fixture system that will have 4 positions, and want to be able to create files automatically to send to the CNC. My plan is to have 4 files in each part directory, say 11.txt, 12.txt, 13.txt, and 14.txt, as well as a header.txt and footer.txt... then I would copy the file from each part corresponding to the place we want to run it in, and put those in a directory. Then, use the "cat" command to create a file.

Code:
cat header.txt 11.txt 12.txt 13.txt 14.txt footer.txt > CNC.txt

Apparently the equivalent of a .bat file is a "bash script" in Linux... Unfortunately the guides I found, even the "basic" ones, seem to jump straight in and miss a bunch of points. I don't know what file extension to create, and if it takes plain terminal commands (I assume so?).

As I guess I have this:
Code:
#!/bin/bash  <--- I see this in the tutorials, but they don't say why it's there. I assume it's a library file of some sort. 
cd /directory
cat header.txt 11.txt 12.txt 13.txt 14.txt footer.txt > CNC.txt

What do I need to make this a working file that anyone could double click when they need to do this? The keyboard is not normally connected to the PC (and there's nowhere to put it), so hopefully the operator won't have to type a password in. I'm also open to suggestions if there's a better way to do it in general.
SUPERPWN
(12 items)
 
  
CPUMotherboardGraphicsRAM
Core i5 4670K Asus z87-Pro MSI GTX 1080 Aero 32GB DDR3 Gskill Ripjaws 
Hard DriveOSMonitorMonitor
4TB Seagate Windows 8 x64 Overlord x270 OC HP ZR27 
MonitorKeyboardPowerAudio
LG34UM94 G-Tune Topre Realforce 800w Yulong D100 DAC with Denon D7000 headphones 
  hide details  
Reply
SUPERPWN
(12 items)
 
  
CPUMotherboardGraphicsRAM
Core i5 4670K Asus z87-Pro MSI GTX 1080 Aero 32GB DDR3 Gskill Ripjaws 
Hard DriveOSMonitorMonitor
4TB Seagate Windows 8 x64 Overlord x270 OC HP ZR27 
MonitorKeyboardPowerAudio
LG34UM94 G-Tune Topre Realforce 800w Yulong D100 DAC with Denon D7000 headphones 
  hide details  
Reply
post #2 of 9
There is no file extension, or rather you don't need one but you can make it whatever you want.

To answer why the "#!/bin/bash" or "#!/bin/sh", http://stackoverflow.com/questions/8967902/why-do-you-need-to-put-bin-bash-at-the-beginning-of-a-script-file



I'm going to start with the most basic of questions that is easily overlooked a lot... did you make the file executable via chmod +x or any other of the dozen methods?
post #3 of 9
I'm definitely no expert, but I know a bit about bash scripting (which is what you want).

So, in Linux, file extensions aren't very important. You can name it whatever you want, though I usually do *.sh for consistency.

To run it, you want to do chmod +x filename.sh. This will mark the executable bit active for the file and let you run it from the command line by just typing the name of the file, like ./filename.sh. I had never tried running a shell script from the GUI, but I just tested it out with KDE (using dolphin as my file browser) and it worked just fine.

The #!/bin/bash is metadata that tells the computer to run the script in the bash shell, as opposed to something like sh (/bin/sh), which also comes by default on Linux but is less feature-rich.

As a side note, usually in Linux you do things like this from the command line. If there's no keyboard on the computer, have you considered setting up SSH so you can remotely access the computer?
Edited by Waffleboy - 8/7/13 at 5:47pm
Workstation
(19 items)
 
  
CPUMotherboardGraphicsGraphics
Intel i7 920 c0 @ 3.50 Asus Sabertooth X58 Nvidia gtx 570 Nvidia gtx 210 
RAMHard DriveOptical DriveOptical Drive
12 GB (Patriot 4GB DDR3 1600 Mhz + G.Skill Ripj... OCZ Vertex II 60GB + x2 WD 1TB + WD 500 GB Lite-On DVD Burner LG Blu Ray Burner 
OSMonitorMonitorMonitor
Windows 8 Professional x64, Arch Linux x64 Samsung 22 inch 1920x1080 60Hz Asus 23 inch 1920x1080 IPS Acer 19 inch 1600x900 
KeyboardPowerCaseMouse
Logitech g11 Corsair 750 Watt NZXT Tempest Razer deathadder 3500 dpi 
Mouse PadAudioAudio
OCZ Audigy SE Sony MDR-V6 
  hide details  
Reply
Workstation
(19 items)
 
  
CPUMotherboardGraphicsGraphics
Intel i7 920 c0 @ 3.50 Asus Sabertooth X58 Nvidia gtx 570 Nvidia gtx 210 
RAMHard DriveOptical DriveOptical Drive
12 GB (Patriot 4GB DDR3 1600 Mhz + G.Skill Ripj... OCZ Vertex II 60GB + x2 WD 1TB + WD 500 GB Lite-On DVD Burner LG Blu Ray Burner 
OSMonitorMonitorMonitor
Windows 8 Professional x64, Arch Linux x64 Samsung 22 inch 1920x1080 60Hz Asus 23 inch 1920x1080 IPS Acer 19 inch 1600x900 
KeyboardPowerCaseMouse
Logitech g11 Corsair 750 Watt NZXT Tempest Razer deathadder 3500 dpi 
Mouse PadAudioAudio
OCZ Audigy SE Sony MDR-V6 
  hide details  
Reply
post #4 of 9
Quote:
Originally Posted by Crazy9000 View Post

I'm currently using a linux machine running Ubuntu 10.10 to send files to a CNC machine via GtkTerm.

We're moving to a new fixture system that will have 4 positions, and want to be able to create files automatically to send to the CNC. My plan is to have 4 files in each part directory, say 11.txt, 12.txt, 13.txt, and 14.txt, as well as a header.txt and footer.txt... then I would copy the file from each part corresponding to the place we want to run it in, and put those in a directory. Then, use the "cat" command to create a file.

Code:
cat header.txt 11.txt 12.txt 13.txt 14.txt footer.txt > CNC.txt

Apparently the equivalent of a .bat file is a "bash script" in Linux... Unfortunately the guides I found, even the "basic" ones, seem to jump straight in and miss a bunch of points. I don't know what file extension to create, and if it takes plain terminal commands (I assume so?).

As I guess I have this:
Code:
#!/bin/bash  <--- I see this in the tutorials, but they don't say why it's there. I assume it's a library file of some sort. 
cd /directory
cat header.txt 11.txt 12.txt 13.txt 14.txt footer.txt > CNC.txt

What do I need to make this a working file that anyone could double click when they need to do this? The keyboard is not normally connected to the PC (and there's nowhere to put it), so hopefully the operator won't have to type a password in. I'm also open to suggestions if there's a better way to do it in general.

#!/bin/bash tells the kernel what interpreter to use to execute the script. When a script is flagged as executeable and attempted to be executed (i.e. double clicking, or typing the normal name and pressing enter) with no interpreter (i.e. not "sh scriptname.sh" which would explicity interpret the script with sh) In this case #!/bin/bash tells it to use the GNU Bourne Again SHell.

So, to make your script executable you simply need to execute "chmod +x scriptname"

Presuming your script doesn't need root permissions to create the "CNC.txt" file you should be fine with no need to type a password.
If you do need root permissions, consider creating a work directory that it won't need elevated permissions to write to, and then changing it to " > /absolute/path/to/CNC.txt"

Anyways, hope you find this information at least somewhat helpful.
    
CPUMotherboardGraphicsRAM
Core i7 920 D0 4.2ghz HT (1.3625v) Asus R3E 2xGTX 460 (non SLi, no overclock) 6x2gb G.skill @ 6-8-6-24-1T 
Hard DriveOptical DriveOSMonitor
WD-VR 300GBx1, 2xWD 1tb,2x60gb Agility Some crappy combo burner... Arch x64 3xDell U2410f rev A02 
KeyboardPowerCaseMouse
X-Armor U9BL TT Toughpower 1200w (NTB more efficient) Mountain Mods Pinnacle 24 CYO Roccat Kone (R.I.P. A4Tech x7) 
Mouse Pad
Steelpad Experience I-1 
  hide details  
Reply
    
CPUMotherboardGraphicsRAM
Core i7 920 D0 4.2ghz HT (1.3625v) Asus R3E 2xGTX 460 (non SLi, no overclock) 6x2gb G.skill @ 6-8-6-24-1T 
Hard DriveOptical DriveOSMonitor
WD-VR 300GBx1, 2xWD 1tb,2x60gb Agility Some crappy combo burner... Arch x64 3xDell U2410f rev A02 
KeyboardPowerCaseMouse
X-Armor U9BL TT Toughpower 1200w (NTB more efficient) Mountain Mods Pinnacle 24 CYO Roccat Kone (R.I.P. A4Tech x7) 
Mouse Pad
Steelpad Experience I-1 
  hide details  
Reply
post #5 of 9
Thread Starter 
Quote:
Originally Posted by Shrak View Post

There is no file extension, or rather you don't need one but you can make it whatever you want.

I'm going to start with the most basic of questions that is easily overlooked a lot... did you make the file executable via chmod +x or any other of the dozen methods?

I didn't do that, done thumb.gif.
Quote:
Originally Posted by Waffleboy View Post


As a side note, usually in Linux you do things like this from the command line. If there's no keyboard on the computer, have you considered setting up SSH so you can remotely access the computer?
Well here's the computer, except normally there isn't the keyboard (monocolor CRT is the CNC control):


SSH would mean the CNC operator (me probably xD) would have to walk over to another computer every time he wanted to run the command. It would work, but would be much better to run the command entirely on the linux computer.
Quote:
Originally Posted by Xaero252 View Post

#!/bin/bash tells the kernel what interpreter to use to execute the script. When a script is flagged as executeable and attempted to be executed (i.e. double clicking, or typing the normal name and pressing enter) with no interpreter (i.e. not "sh scriptname.sh" which would explicity interpret the script with sh) In this case #!/bin/bash tells it to use the GNU Bourne Again SHell.


Anyways, hope you find this information at least somewhat helpful.

For some reason your post gave me the idea to remove the bash line at the start of the file. Now I can double click the file, select "run in terminal" and it works!


Thanks everyone.
SUPERPWN
(12 items)
 
  
CPUMotherboardGraphicsRAM
Core i5 4670K Asus z87-Pro MSI GTX 1080 Aero 32GB DDR3 Gskill Ripjaws 
Hard DriveOSMonitorMonitor
4TB Seagate Windows 8 x64 Overlord x270 OC HP ZR27 
MonitorKeyboardPowerAudio
LG34UM94 G-Tune Topre Realforce 800w Yulong D100 DAC with Denon D7000 headphones 
  hide details  
Reply
SUPERPWN
(12 items)
 
  
CPUMotherboardGraphicsRAM
Core i5 4670K Asus z87-Pro MSI GTX 1080 Aero 32GB DDR3 Gskill Ripjaws 
Hard DriveOSMonitorMonitor
4TB Seagate Windows 8 x64 Overlord x270 OC HP ZR27 
MonitorKeyboardPowerAudio
LG34UM94 G-Tune Topre Realforce 800w Yulong D100 DAC with Denon D7000 headphones 
  hide details  
Reply
post #6 of 9
Quote:
Originally Posted by Crazy9000 View Post

SSH would mean the CNC operator (me probably xD) would have to walk over to another computer every time he wanted to run the command. It would work, but would be much better to run the command entirely on the linux computer.

Gotcha. Do you need to run the script at a predictable time every day/week/whatever, or is it just when you need it? If the former, you can set it up to run automatically.
Workstation
(19 items)
 
  
CPUMotherboardGraphicsGraphics
Intel i7 920 c0 @ 3.50 Asus Sabertooth X58 Nvidia gtx 570 Nvidia gtx 210 
RAMHard DriveOptical DriveOptical Drive
12 GB (Patriot 4GB DDR3 1600 Mhz + G.Skill Ripj... OCZ Vertex II 60GB + x2 WD 1TB + WD 500 GB Lite-On DVD Burner LG Blu Ray Burner 
OSMonitorMonitorMonitor
Windows 8 Professional x64, Arch Linux x64 Samsung 22 inch 1920x1080 60Hz Asus 23 inch 1920x1080 IPS Acer 19 inch 1600x900 
KeyboardPowerCaseMouse
Logitech g11 Corsair 750 Watt NZXT Tempest Razer deathadder 3500 dpi 
Mouse PadAudioAudio
OCZ Audigy SE Sony MDR-V6 
  hide details  
Reply
Workstation
(19 items)
 
  
CPUMotherboardGraphicsGraphics
Intel i7 920 c0 @ 3.50 Asus Sabertooth X58 Nvidia gtx 570 Nvidia gtx 210 
RAMHard DriveOptical DriveOptical Drive
12 GB (Patriot 4GB DDR3 1600 Mhz + G.Skill Ripj... OCZ Vertex II 60GB + x2 WD 1TB + WD 500 GB Lite-On DVD Burner LG Blu Ray Burner 
OSMonitorMonitorMonitor
Windows 8 Professional x64, Arch Linux x64 Samsung 22 inch 1920x1080 60Hz Asus 23 inch 1920x1080 IPS Acer 19 inch 1600x900 
KeyboardPowerCaseMouse
Logitech g11 Corsair 750 Watt NZXT Tempest Razer deathadder 3500 dpi 
Mouse PadAudioAudio
OCZ Audigy SE Sony MDR-V6 
  hide details  
Reply
post #7 of 9
Quote:
Originally Posted by Crazy9000 View Post

SSH would mean the CNC operator (me probably xD) would have to walk over to another computer every time he wanted to run the command. It would work, but would be much better to run the command entirely on the linux computer.

Gotcha. Do you need to run the script at a predictable time every day/week/whatever, or is it just when you need it? If the former, you can set it up to run automatically.
Workstation
(19 items)
 
  
CPUMotherboardGraphicsGraphics
Intel i7 920 c0 @ 3.50 Asus Sabertooth X58 Nvidia gtx 570 Nvidia gtx 210 
RAMHard DriveOptical DriveOptical Drive
12 GB (Patriot 4GB DDR3 1600 Mhz + G.Skill Ripj... OCZ Vertex II 60GB + x2 WD 1TB + WD 500 GB Lite-On DVD Burner LG Blu Ray Burner 
OSMonitorMonitorMonitor
Windows 8 Professional x64, Arch Linux x64 Samsung 22 inch 1920x1080 60Hz Asus 23 inch 1920x1080 IPS Acer 19 inch 1600x900 
KeyboardPowerCaseMouse
Logitech g11 Corsair 750 Watt NZXT Tempest Razer deathadder 3500 dpi 
Mouse PadAudioAudio
OCZ Audigy SE Sony MDR-V6 
  hide details  
Reply
Workstation
(19 items)
 
  
CPUMotherboardGraphicsGraphics
Intel i7 920 c0 @ 3.50 Asus Sabertooth X58 Nvidia gtx 570 Nvidia gtx 210 
RAMHard DriveOptical DriveOptical Drive
12 GB (Patriot 4GB DDR3 1600 Mhz + G.Skill Ripj... OCZ Vertex II 60GB + x2 WD 1TB + WD 500 GB Lite-On DVD Burner LG Blu Ray Burner 
OSMonitorMonitorMonitor
Windows 8 Professional x64, Arch Linux x64 Samsung 22 inch 1920x1080 60Hz Asus 23 inch 1920x1080 IPS Acer 19 inch 1600x900 
KeyboardPowerCaseMouse
Logitech g11 Corsair 750 Watt NZXT Tempest Razer deathadder 3500 dpi 
Mouse PadAudioAudio
OCZ Audigy SE Sony MDR-V6 
  hide details  
Reply
post #8 of 9
Thread Starter 
Quote:
Originally Posted by Waffleboy View Post

Gotcha. Do you need to run the script at a predictable time every day/week/whatever, or is it just when you need it? If the former, you can set it up to run automatically.

It would be run as needed. For example, if I was in the business of making GPU waterblocks (I'm not tongue.gif), I would have folders on the NAS for each GPU, like 780,760,680,650,660ti,570. Then, in each of those folders would be gcode files named 11.txt, 12.txt 13.txt 14.txt.

With this system, you can take files from each folder as needed to make a custom batch of parts to run, as opposed to having to run a whole table of the 570 blocks.



So I will be taking the 11.txt from the 570 folder, 12.txt from the 780 folder, 13.txt from the 680 folder, and then 14.txt from the 760 folder. The script will make these into one file I can send to the CNC to run them all in one go. Then maybe the next run would be a 780, 760, 660ti, and 650. I just have to take the files from the position I run those in, put them into the folder, and run the command again.

If I had the 780 always run in position 11, I couldn't ever run 3 runs at once of it, or run another program that's position 11 at the same time.
SUPERPWN
(12 items)
 
  
CPUMotherboardGraphicsRAM
Core i5 4670K Asus z87-Pro MSI GTX 1080 Aero 32GB DDR3 Gskill Ripjaws 
Hard DriveOSMonitorMonitor
4TB Seagate Windows 8 x64 Overlord x270 OC HP ZR27 
MonitorKeyboardPowerAudio
LG34UM94 G-Tune Topre Realforce 800w Yulong D100 DAC with Denon D7000 headphones 
  hide details  
Reply
SUPERPWN
(12 items)
 
  
CPUMotherboardGraphicsRAM
Core i5 4670K Asus z87-Pro MSI GTX 1080 Aero 32GB DDR3 Gskill Ripjaws 
Hard DriveOSMonitorMonitor
4TB Seagate Windows 8 x64 Overlord x270 OC HP ZR27 
MonitorKeyboardPowerAudio
LG34UM94 G-Tune Topre Realforce 800w Yulong D100 DAC with Denon D7000 headphones 
  hide details  
Reply
post #9 of 9
You can make it a single "double-click" to execute shortcut on the desktop by using the "Add Launcher" context menu option on the desktop.

From there you can put "gnome-terminal -e /path/to/script" in the command field for the Launcher. This will cause it to open a terminal and run the script inside it. If you don't want the terminal to show you can just do "sh /path/to/script" and it will run transparently in the background.
    
CPUMotherboardGraphicsRAM
Core i7 920 D0 4.2ghz HT (1.3625v) Asus R3E 2xGTX 460 (non SLi, no overclock) 6x2gb G.skill @ 6-8-6-24-1T 
Hard DriveOptical DriveOSMonitor
WD-VR 300GBx1, 2xWD 1tb,2x60gb Agility Some crappy combo burner... Arch x64 3xDell U2410f rev A02 
KeyboardPowerCaseMouse
X-Armor U9BL TT Toughpower 1200w (NTB more efficient) Mountain Mods Pinnacle 24 CYO Roccat Kone (R.I.P. A4Tech x7) 
Mouse Pad
Steelpad Experience I-1 
  hide details  
Reply
    
CPUMotherboardGraphicsRAM
Core i7 920 D0 4.2ghz HT (1.3625v) Asus R3E 2xGTX 460 (non SLi, no overclock) 6x2gb G.skill @ 6-8-6-24-1T 
Hard DriveOptical DriveOSMonitor
WD-VR 300GBx1, 2xWD 1tb,2x60gb Agility Some crappy combo burner... Arch x64 3xDell U2410f rev A02 
KeyboardPowerCaseMouse
X-Armor U9BL TT Toughpower 1200w (NTB more efficient) Mountain Mods Pinnacle 24 CYO Roccat Kone (R.I.P. A4Tech x7) 
Mouse Pad
Steelpad Experience I-1 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Linux, Unix
Overclock.net › Forums › Software, Programming and Coding › Operating Systems › Linux, Unix › Help with Linux "bat file"