rc.common not run on mac os x - macos

I want to run a shell script on startup
by google ,I found that I could add shell in rc.common
so I added the code below at the end of rc.common
is it a permission problem?
## rc.common test ##
touch ~/test.txt
reboot,there is no test.txt in my user fold
when I test it in terminal manualy ,it's ok
ls -l /etc/rc.common
-rw-r--r-- 1 guirong wheel 1737 3 30 22:36 /etc/rc.common
where is the problem? my system verison is 10.7.3
is it not ran by default in os x?

Just as an added bit of information about what was happening; /etc/rc.common runs as root, so when you were touching the file at ~/test.txt it would have been ending up in /var/root (the root user's home directory)

If you want the script to be run only for the current user, you should use ~/.bashrc instead
Later edit: I misread your question. If you want something to run at startup, you should look into launchd here

Related

Cannot change com.apple.atrun.plist even with root permissions

I'm using OSX Mojave and I've been wanting to use the at command to run scripts at certain times, but I've discovered that I need to change its plist file in order to use it. Right now, one of the attributes in it is Disabled=true which of course, isn't what I want.
I've gone to the ends of the earth to try to change that. I tried XCode, Pref Setter, chmod, chown, vim, and doing all of that in root. No matter what, it always says, "readonly file" or "You do not have permission."
Are plists supposed to be immutable? I'm pretty sure they aren't. Here is some of the things I've tried.
~root# id
uid=0(root) gid=0(wheel) groups=0(wheel ...
~root# atrun=/System/Library/LaunchDaemons/com.apple.atrun.plist
~root# chmod 777 $atrun
chmod: Unable to change file mode on
/System/Library/LaunchDaemons/com.apple.atrun.plist: Operation not permitted
~root# ls -l $atrun
-rw-r--r-- 1 root wheel 444 Aug 22 23:11 /System/Library/LaunchDaemons/com.apple.atrun.plist
Make a copy of com.apple.atrun.plist from /System/Library/LaunchDaemons
into your home directory or wherever you want to work on it.
Open com.apple.atrun.plist with Xcode and the settings will show up in user readable form.
Change the setting for "Disabled" from 1 to 0 then save and exit Xcode
Copy your changed com.apple.atrun.plist file to /Library/LaunchDaemons
This can be manually launched to enable batch.

How create .gdbinit in home directory (Mac OS)

l
Hello everybody,I need to create a .gdbinit file to use the command "go" on gdb.
Our prof told us to create it in home directory and it was simple.
On Linux all I needed was to being root.
Now with Mac I can't create the file even if I am root.
From command line if I type " touch .gdbinit " or if I create the file in a different directory and try to move it in home the result is always "Operation not supported".
Now I am very confused because I thought to be a god as root.
Maybe this is true on Linux,Mac is different.
However someone know how to create a .gdbinit file in home?
I work on Sierra 10.12.6
There is no reason why this shouldn't work:
cd
touch .gdbinit
Now check it exists:
ls -la .gdbinit

.bash_profile won't open

When I run open .bash_profile a new terminal opens and
Last login: Wed Nov 30 19:01:22 on ttys004
/Users/MyName/.bash_profile ; exit;
➜ ~ /Users/MyName/.bash_profile ; exit;
[Process completed]
My permissions are
-rwxr-xr-x# 1 MyName staff 639 Nov 30 19:02 .bash_profile
Also, when I run ls -la, .bash_profile is colored red. I don't know why. It wasn't like that before.
All I was trying to do was create an alias, but now I can't even open my .bash_profile.
tl;dr
To ensure that you open a file in your default text editor using the macOS open CLI, use:
open -t ~/.bash_profile
Otherwise, if the file needn't be excecutable, run chmod -x <file> (chmod -x ~/.bash_profile, in this case) to make open behave like it did before.
From you question I infer that you're on macOS (OS X).
What the macOS open CLI does when passed a file depends on the file's suffix (extension), and, in the absence of one, on whether the file has the executable (r) permissions bit(s) set (if not, the file opens in the standard text editor, which is what you saw before).
A file displaying in red when you use ls -a (the -a being necessary to show hidden items such as .bash_profile), implies that the file is indeed executable by you.
A suffix-less executable (text) file causes open to run it in a new terminal window as a shell script, which is what you're seeing.
In other words: at some point, unbeknownst to you, executable permissions were assigned to ~/.bash_profile, which explains the change in behavior.
However, there is no need for ~/.bash_profile to be executable, because it is sourced by Bash on startup.
As stated above, either remove the executable permissions, or simply use open -t to open it.

How to stop XCode replacing system commands in run script phase?

My situation:
OSX 10.9 + Xcode 4.6.3 + run script phase + script:
#!/bin/bash
/usr/bin/svn --version
ls -la /usr/bin/svn
exit 1
I receive the outputs:
svn, version 1.6.18 (r1303927)
-rwxr-xr-x 1 root wheel 14224 26 oct 05:08 /usr/bin/svn
This is unbelievable. The size and date of the real file correspond with v1.7.10 (which is really placed at the path /usr/bin/svn) but calling this file from within XCode will call the /Application/Xcode463.app/Content/Developer/usr/bin/svn command!
How can I prevent this? How can I call my default /usr/bin/svn command?
How is it possible to do hidden replacement of one command with another without replacing the real file?
The right answer is that /usr/bin/svn is a link to the xcrun wrapper. Command to see it:
nm /usr/bin/svn
So root cause of issue is next command:
xcode-select --print-path
in the run script phase will print current Xcode instead of system default Xcode.

Run script on mac prompt "Permission denied"

I'm new to mac with not familiar on terminal command, i put the dvtcolorconvert.rb file on root directory of my volume, this ruby script can converting xcode 3 themes into xcode 4 themes format, which is xxxxxxxx.dvtcolortheme format.
Then run the script /dvtcolorconvert.rb ~/Themes/ObsidianCode.xccolortheme on terminal, but it's always prompt "Permission denied".
what's wrong with this? Anybody can help me solve this problem? Thanks.
Did you give yourself the rights to execute the script?
The following command as super user will do this for you:
sudo chmod 755 'filename'
For details you should read the man page of chmod.
Please read the whole answer before attempting to run with sudo
Try running sudo /dvtcolorconvert.rb ~/Themes/ObsidianCode.xccolortheme
The sudo command executes the commands which follow it with 'superuser' or 'root' privileges. This should allow you to execute almost anything from the command line. That said, DON'T DO THIS! If you are running a script on your computer and don't need it to access core components of your operating system (I'm guessing you're not since you are invoking the script on something inside your home directory (~/)), then it should be running from your home directory, ie:
~/dvtcolorconvert.rb ~/Themes/ObsidianCode.xccolortheme
Move it to ~/ or a sub directory and execute from there. You should never have permission issues there and there wont be a risk of it accessing or modifying anything critical to your OS.
If you are still having problems you can check the permissions on the file by running ls -l while in the same directory as the ruby script. You will get something like this:
$ ls -l
total 13
drwxr-xr-x 4 or019268 Administ 12288 Apr 10 18:14 TestWizard
drwxr-xr-x 4 or019268 Administ 4096 Aug 27 12:41 Wizard.Controls
drwxr-xr-x 5 or019268 Administ 8192 Sep 5 00:03 Wizard.UI
-rw-r--r-- 1 or019268 Administ 1375 Sep 5 00:03 readme.txt
You will notice that the readme.txt file says -rw-r--r-- on the left. This shows the permissions for that file. The 9 characters from the right can be split into groups of 3 characters of 'rwx' (read, write, execute). If I want to add execute rights to this file I would execute chmod 755 readme.txt and that permissions portion would become rwxr-xr-x. I can now execute this file if I want to by running ./readme.txt (./ tells the bash to look in the current directory for the intended command rather that search the $PATH variable).
schluchc alludes to looking at the man page for chmod, do this by running man chmod. This is the best way to get documentation on a given command, man <command>
In my case, I had made a stupid typo in the shebang.
So in case someone else on with fat fingers stumbles across this question:
Whoops: #!/usr/local/bin ruby
I meant to write: #!/usr/bin/env ruby
The vague error ZSH gives sent me down the wrong path:
ZSH: zsh: permission denied: ./foo.rb
Bash: bash: ./foo.rb: /usr/local/bin: bad interpreter: Permission denied
You should run the script as 'superuser', just add 'sudo' in front of the command and type your password when prompted.
So try:
sudo /dvtcolorconvert.rb ~/Themes/ObsidianCode.xccolortheme
If this doesn't work, try adapting the permissions:
sudo chmod 755 /dvtcolorconvert.rb
sudo chmod 755 ~/Themes/ObsidianCode.xccolortheme
To run in the administrator mode in mac
sudo su
use source before file name,,
like my file which i want to run from terminal is ./jay/bin/activate
so i used command "source ./jay/bin/activate"
Check the permissions on your Ruby script (may not have execute permission), your theme file and directory (in case it can't read the theme or tries to create other themes in there), and the directory you're in when you run the script (in case it makes temporary files in the current directory rather then /tmp).
Any one of them could be causing you grief.

Resources