How Can I Make A Terminal Command Permanent?

Joined
Dec 8, 2010
Messages
22
Reaction score
0
Points
1
Hi All,

We posted this on the Apple Forum, but haven't had any responses yet, just wondering if anyone here can help us...

After months of frustration trying to get our old FSG 3 Freecom Nas to work in OSX Lion, we finally discovered something that is helping. We can now see our NAS drive under Lion, but the fix is only temporary and we're looking for a way to make it permanent using Terminal (or any other method).

I basically read this article:
Fixing SMB issues with OSX Lion | Software is too expensive to build cheaply….

and the terminal command:
sudo sysctl -w net.smb.fs.kern_deprecatePreXPServers=0

allows me to see and connect to my NAS, but after a reboot, connectivity disappears and I have to do it again. In order to make the fix permanent, the article suggests editing the file /etc/sysctl.conf

this file just doesn't exist on my machine under Lion...

Could someone help with instructions as to what I would need to do in Terminal (or any other way) to create and add this command into the file to make this a permanent fix????

Thank you so much

T
 
OP
T
Joined
Dec 8, 2010
Messages
22
Reaction score
0
Points
1
Thank you so much for your help Louishen, I'm a little bit lost by the use of shell scripts though... I'm pretty new to Macs, and this is a little bit beyond me. Are there any GUI programs that I could copy and paste the terminal command into perhaps?

Thank you again for all your help.

T

 

vansmith

Senior Member
Joined
Oct 19, 2008
Messages
19,924
Reaction score
559
Points
113
Location
Queensland
Your Mac's Specs
Mini (2014, 2018, 2020), MBA (2020), iPad Pro (2018), iPhone 13 Pro Max, Watch (S6)
You can simply paste the command into a plain text document and save it with the ".sh" extension. There's your shell script. ;)

Note: If you're using TextEdit to create the script, you'll need to make sure it's in Plain Text mode (Format > Make Plain Text). If you don't, the file will be saved as rich text which won't be interpreted properly.
 
OP
T
Joined
Dec 8, 2010
Messages
22
Reaction score
0
Points
1
Hi vansmith, thanks for this - I'll give it a go!

Really appreciate all the help on this forum, I'm totally new to this (not so long ago switched from a PC) so this is a really big help.

All the best and thanks again

T

You can simply paste the command into a plain text document and save it with the ".sh" extension. There's your shell script. ;)

Note: If you're using TextEdit to create the script, you'll need to make sure it's in Plain Text mode (Format > Make Plain Text). If you don't, the file will be saved as rich text which won't be interpreted properly.
 
OP
T
Joined
Dec 8, 2010
Messages
22
Reaction score
0
Points
1
Hi vansmith,

I'm having a bit of trouble getting this to work. This is what I did:
1) I Copied the command:
sudo sysctl -w net.smb.fs.kern_deprecatePreXPServers=0
into Text Edit, Chose Format > Make Plain Text and saved it on my desktop as NAS.sh
2) I then went to the folder: System > Library > Startupitems and created a subfolder called NAS and moved the Nas.sh file into it.
3) I then restarted my MBP and tried to connect to my NAS drive, but it didn't work! I just got the usual cannot connect error.

Have I done something wrong in some part of these steps?

Thanks

T


You can simply paste the command into a plain text document and save it with the ".sh" extension. There's your shell script. ;)

Note: If you're using TextEdit to create the script, you'll need to make sure it's in Plain Text mode (Format > Make Plain Text). If you don't, the file will be saved as rich text which won't be interpreted properly.
 

vansmith

Senior Member
Joined
Oct 19, 2008
Messages
19,924
Reaction score
559
Points
113
Location
Queensland
Your Mac's Specs
Mini (2014, 2018, 2020), MBA (2020), iPad Pro (2018), iPhone 13 Pro Max, Watch (S6)
One of the key sentences from that page which lacks explanation is the following:
An executable shell script is just another program as far as Unix is concerned, so you can configure scripts to start on login from there
The key here is the "executable" part and unfortunately, the article doesn't explain how to do this.

Execute the following to make it excutable:
Code:
sudo chmod +x /System/Library/StartupItems/NAS/Nas.sh
If you don't make it executable, the script doesn't appear to be something that needs to be executed. By making it executable, you're essentially telling the OS that this script is meant to be executed.
 
OP
T
Joined
Dec 8, 2010
Messages
22
Reaction score
0
Points
1
Thanks again vansmith. I totally get the principle of what you're saying, but not sure I have executed it right... I now have one file (in the same location, still named NAS.sh, but I added the extra command in so it reads like this:

sudo chmod +x /System/Library/StartupItems/NAS/Nas.sh
sudo sysctl -w net.smb.fs.kern_deprecatePreXPServers=0

Is this right, or do I need a seperate file called something else inside the startup folder which Lion will read and from that it'll execute the NAS shell command script?

Apologies for all the questions

T

One of the key sentences from that page which lacks explanation is the following:The key here is the "executable" part and unfortunately, the article doesn't explain how to do this.

Execute the following to make it excutable:
Code:
sudo chmod +x /System/Library/StartupItems/NAS/Nas.sh
If you don't make it executable, the script doesn't appear to be something that needs to be executed. By making it executable, you're essentially telling the OS that this script is meant to be executed.
 

vansmith

Senior Member
Joined
Oct 19, 2008
Messages
19,924
Reaction score
559
Points
113
Location
Queensland
Your Mac's Specs
Mini (2014, 2018, 2020), MBA (2020), iPad Pro (2018), iPhone 13 Pro Max, Watch (S6)
You don't add the chmod line to your script - you execute it to make your one line script executable. So, remove it from your script (such that you only have the one relevant line), open up a Terminal window and execute the chmod command I provided.
 
OP
T
Joined
Dec 8, 2010
Messages
22
Reaction score
0
Points
1
Aarrggh. still can't get this to work. So, sorry for all the questions. One last thing: my MBP has a password on it, would this prevent the script from autorunning on startup?

It's the only thing I could think of as I've followed everything else to the letter.

Apologies again for bothering you so much with this....

Thanks

T


You don't add the chmod line to your script - you execute it to make your one line script executable. So, remove it from your script (such that you only have the one relevant line), open up a Terminal window and execute the chmod command I provided.
 

vansmith

Senior Member
Joined
Oct 19, 2008
Messages
19,924
Reaction score
559
Points
113
Location
Queensland
Your Mac's Specs
Mini (2014, 2018, 2020), MBA (2020), iPad Pro (2018), iPhone 13 Pro Max, Watch (S6)
I'm going to guess that the script is executing before sysctl is available or sysctl is erroring out. For instance, it might be trying to set a value that is overwritten during the boot process or is might not have access to resources that it needs when it executes (in other words, it executes too early in the boot process).

Instead of fighting with this, you might want to try the more flexible launchd. Take a look at this article.
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top