Sponsored Content
Top Forums Shell Programming and Scripting Issue with shutdown command in script (MacOS High Sierra) Post 303032218 by Neo on Wednesday 13th of March 2019 11:19:26 PM
Old 03-14-2019
Quote:
Originally Posted by Neo
You don't need to sudo, just run it from the admin account on the Mac and move on to other tasks.
Quote:

LMHmedchem wrote:

Some of my issue was how to go about running from the admin account. The account I am in is already administrator , but I get permission denied when I try to run shutdown from a script. To authorize shutdown, I can run the script as, sudo scriptname , or I can su and then call the script.The default root account is disabled on many Mac installations, so you are not supposed to be able to change the user to root without activating the root account first. Please let me know if I am not correct about any of this.
No, you are not really correct. I have 4 Macs which I work on extensively, and I do not use MacOS as you describe. When I login as "Neo", which is a user account with MacOS Admin rights, I do not use my "Neo" account to run scripts which need to run as root. I simply do this:

Code:
sudo -i

...then I am into a terminal window and if I need a cron file to run (for example) with superuser privs, I install a root crontab. I don't create a "Neo" crontab and then write a bunch of "goofy" (sorry, but that's the first word that comes to mind, it is not directed at you or your work) sudo wrappers around a "Neo crontab script" to force the "Neo" account do accomplish what I can easily do running the script as root in the root account.

As a side note, I think it was also you who, in a earlier post (LMHmedchem, but I might be mistaken as I've busy coding sorry and don't have time to go back and review your older posts, my bad) , was working "as an exercise" to figure out how to close the MacOS terminal window in a script when the shell exits, and I read (in reply to that post) a lot of people replying to help you "in your exercise" which was confusing to me because this is simply a " 10 second preferences" selection in the MacOS terminal config dialog box.

You seemingly are asking questions, "as exercises" to solve problems that do not exist and that's OK "as exercises" and I encourage you to do so in these forums and I encourage everyone to reply who has time to reply; but honestly, you seem to have the luxury of an abundance of free time on your hands if you need to create problems in order to solve them. That's OK too. However, let me be clear since you asked me:

I write a lot of small task-related scripts on MacOS and I work in a quite robust development environment on the Mac and my "main development box" is a 12 core Mac Pro, and if I need to run a script to do "root things", like a crontab script which needs root privs , I run this script as root, configured as the root user from the root account. Boom. Task done. Move on to the next task. I never run scripts as "Neo" wrapped in a lot of "sudo" code to accomplish tasks as the superuser which I can do as the root user directly. Sorry, but why would I waste my time doing that? I have a lot to do and never enough time to do it and if I worked 12 hours a day everyday, I would still not have enough time to so all the things I need to get done in development, so I need to get things done quickly and not turn 30 second tasks into days of exploring MacOS. Hey, that's just me and more power to you if you have a lot of free time to do these "turn a one minute routine task into days of Q&A" experience.

The same is true for the earlier post about "how to close a MacOS terminal window when the shell exits"... I have shells exiting in MacOS terminal windows all the time, and if I wanted or needed those terminal windows to close when the shell exits, I would configure the terminal preference to "close window on shell exit..."

MacOS is great and I would not develop code on any other platform. If you or anyone has the luxury of a lot of time to play around with MacOS and do things in a more "difficult" way than the "10 second routine way" then by all means, go for it; but for me (and you asked me directly), when I read your posts my "inner thoughts" are "wow, this guy has a lot more free time than I do because he spends days on tasks which I can do one minute" and you seem to enjoy it; so go for it!

I used to have free time like that many years ago. I'm kinda envious to be honest Smilie
This User Gave Thanks to Neo For This Post:
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Script to force Oracle database shutdown when shutdown immediate does not work

I have Oracle 9i R2 on AIX 5.2. My Database is running in shared server mode (MTS). Sometimes when I shutdown the database it shutsdown cleanly in 4-5 mints and sometimes it takes good 15-20 minutes and then I get some ora-600 errors and only way to shutdown is by opening another session and... (7 Replies)
Discussion started by: aixhp
7 Replies

2. High Performance Computing

High Performance Linpack Compiling Issue

I'm trying to compile Linpack on a Ubuntu cluster. I'm running MPI. I've modified the following values to fit my system TOPdir MPdir LAlib CC LINKER. When compiling I get the following error: (the error is at the end, the other errors in between are because I've ran the script several times so... (0 Replies)
Discussion started by: JPJPJPJP
0 Replies

3. Shell Programming and Scripting

what would a script include to find CPU's %system time high and user time high?

Hi , I am trying to :wall: my head while scripting ..I am really new to this stuff , never did it before :( . how to find cpu's system high time and user time high in a script?? thanks , help would be appreciated ! :) (9 Replies)
Discussion started by: sushwey
9 Replies

4. Shell Programming and Scripting

Exit script when shutdown or reboot command is given

This is probably a simple question, but I'm new with writing scripts for Linux (IPFire in this case) and Google wasn't helpful with this. When creating a script, what is the best and/or proper way to have it exit automatically if the reboot or shutdown command is given? If that's even... (2 Replies)
Discussion started by: bartgrefte
2 Replies

5. UNIX for Beginners Questions & Answers

Capture power button press on MacOs High Sierra?

Hello everyone! I'm developing a MacOs Application in python and I'm having some issues trying to find information related to the power button pressed event. I know that in Ubuntu 14.04 you can find information about it on the acpi folders, but I realized that here in Mac that process is... (0 Replies)
Discussion started by: xedge
0 Replies

6. OS X (Apple)

If you run macOS High Sierra version 10.13.1, be sure to install today's update.

Some hackers found a security hole in macOS High Sierra and tweeted it to the world before telling Apple about the problem. You can see the details from PC Magazine's daily news here: Apple Releases Fix for MacOS High Sierra 'Root' Bug. The original story this morning was published before a patch... (6 Replies)
Discussion started by: Don Cragun
6 Replies

7. UNIX for Beginners Questions & Answers

Linux SuSE SLES 8 error..unable to issue shutdown command

the only way we can power off is if we actually press power button on server. Running on HP DL-G4. from root, when we issue command it just returns to root prompt. (1 Reply)
Discussion started by: amexboy
1 Replies

8. Shell Programming and Scripting

Issue with pwd for script run by double click on script (MacOS High SIerra)

Hello, I have the following script that just archives and clears some log files. #!/bin/bash # script: archive_logs_and_clear # add date to logfile names and copy archive directory # clear logs # change to script directory cd ... (4 Replies)
Discussion started by: LMHmedchem
4 Replies

9. Shell Programming and Scripting

Terminal running bash/rsync script does not close with exit (MacOS High SIerra)

Hello, I am running a bash script to do an rsync back on a computer running MacOS High Sierra. This is the script I am using, #!/bin/bash # main backup location, trailing slash included backup_loc="/Volumes/Archive_Volume/00_macos_backup/" # generic backup function function backup {... (12 Replies)
Discussion started by: LMHmedchem
12 Replies

10. OS X (Apple)

Change Name of Bluetooth Device from Command Line in macOS

Mac Version 10.15.2 (macOS Catalina) Does anyone know how to change the name of a connected bluetooth device from the command line on macOS? I am having trouble with various bluetooth devices which I cannot get the "rename" option in the GUI to "save" properly and so I cannot rename a few... (0 Replies)
Discussion started by: Neo
0 Replies
All times are GMT -4. The time now is 09:48 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy