jeebo
Posts: 69
Joined: Tue Mar 28, 2017 3:55 pm

Shell script won't run just edit

Sat Jun 16, 2018 2:24 pm

Hi guys

I created a shell script which runs from the desktop (createdirectories.sh) which I have put the following

Code: Select all

#!/bin/bash

sudo mkdir /home/pi/usb
sudo mkdir /home/pi/usb/4TB
sudo mkdir /home/pi/usb/2TB1
sudo mkdir /home/pi/usb/2TB2
sudo mkdir /home/pi/usb/2TB3
However when I try to run the file from the desktop, it just opens in text editor. It has a cog icon on the file so looks like it should work correctly.

Can anyone advise what has gone wrong? Or am I just doing something wrong?

DirkS
Posts: 9968
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: Shell script won't run just edit

Sat Jun 16, 2018 2:47 pm

Did you make the file executable?

Code: Select all

chmod +x createdirectories.sh
BTW: do you really need to run that script as root? It will set 'root' as the owner instead of user 'pi'

jeebo
Posts: 69
Joined: Tue Mar 28, 2017 3:55 pm

Re: Shell script won't run just edit

Mon Jun 18, 2018 3:21 pm

Sorry for the delay

The file is as is, so I guess not :(

All I really want to do, is to have a single click file I can run this from, as one of the scripts I want to run (as I dont want to mess with the fstab file) is to click and run the mounting of several USB drives to local drives, to use with samba and for file management.

n67
Posts: 938
Joined: Mon Oct 30, 2017 4:55 pm

Re: Shell script won't run just edit

Mon Jun 18, 2018 5:21 pm

1) To make a clickable icon, you have to create a "something.desktop" file in the ~/Desktop directory. This file is in the typical "INI file" format. For example:

Code: Select all

[Desktop Entry]
Version=1.0
Name=something
Comment=Run the something utility
Exec=/home/pi/MyUtility
Icon=
Terminal=true
Type=Application
Categories=Utility;Application;
Then when you double click the icon, it will run whatever is in the "Exec=" line.

2) Your script looks like something you'd just run once. Once all those directories are created, you're done. Why do you need to run it multiple times?
"L'enfer, c'est les autres"

G fytc hsqr rum umpbq rm qyw rm rfc kmbq md rfgq dmpsk:

Epmu Sn!

J lnacjrw njbruh-carppnanm vxm rb mnuncrwp vh yxbcb!

jeebo
Posts: 69
Joined: Tue Mar 28, 2017 3:55 pm

Re: Shell script won't run just edit

Mon Jun 18, 2018 8:26 pm

Primarily because this was the "test" phase of familiarizing and improving my ability to write scripts.

The next step would be to take the contents of this known working batch file, rename it, and change the content to be, for example:

Code: Select all

sudo mount /dev/sda2 /pi/home/USBDrive
sudo mount /dev/sdb1 /pi/home/USBDrive2Partition1
sudo mount /dev/sdb2 /pi/home/USBDrive2Partition2
sudo mount /dev/sdb3 /pi/home/USBDrive2Partition3
sudo mount /dev/sdb4 /pi/home/USBDrive2Partition4
sudo mount /dev/sdc1 /pi/home/USBDrive3Partition1
sudo mount /dev/sdc2 /pi/home/USBDrive3Partition2
sudo mount /dev/sdc3 /pi/home/USBDrive3Partition3
sudo mount /dev/sdc4 /pi/home/USBDrive3Partition4
sudo mount /dev/sdd1 /pi/home/USBDrive4Partition1
sudo mount /dev/sdd2 /pi/home/USBDruve4Partition2
This is basically going to be a NAS drive, and I dont want to kill the bootloader, by changing fstab, so once I have "mastered" the art of the clickable batch file, then I can run a cron job, or, manually run the file whenever the pi restarts, automatically mounting all of the drives to their respective local folders, making them available for Samba to publish as a public drive.

Hopefully this makes sense?

James

asandford
Posts: 1997
Joined: Mon Dec 31, 2012 12:54 pm
Location: Waterlooville

Re: Shell script won't run just edit

Mon Jun 18, 2018 9:09 pm

Devices 'wander' during boot, so don't expect /dev/sda1 to be the same partition every time.

A better option is to use udev rules with UUIDs to map the partition iDs to mount points.

Return to “General discussion”