'at' command not working - bash

I want to run a backup command at a specific time in bash. Only issue is the at command doesn't seem to work. By this I mean it does not run the command at the specific time
I have tried to use the commands posted here.
If the at command doesn't work are there any other suggestions?
I am trying to run a custom command I put in the /bin directory called backup.
If it helps I am running OS X 10.10 (Yosemite)
Edit
Found out the issue.
Some reason my command will only work outside a script. Hmm

Use:
sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.atrun.plist
From the man atrun:
The atrun utility runs commands queued by at(1). It is invoked periodically by launchd(8) as specified in the
com.apple.atrun.plist property list. By default the property list contains the Disabled key set to true, so
atrun is never invoked.
Execute the following command as root to enable atrun:
launchctl load -w /System/Library/LaunchDaemons/com.apple.atrun.plist

Found the reason why.
It is because the command for some reason didn't work (it did before though)

Related

Bash script for setting up mac keeps skipping commands or simply prints to the console without executing lines

I've been trying to create a bash script that allows me to transfer my existing dev setup to a brand new macbook.
I set up a bash script which is supposed to automate this process but for some reason when I call the script using curl, it doesnt seem to reliably run the whole thing and I cant figure out why that is. example of commands being printed to the console and note executed
If I were to manually enter each line into the terminal and execute, things work as expected however doing so defeats the purpose of the script.
I'll attach some screenshots of the terminal output so you can see the exact issues I'm facing and at which point it behaves oddly.
I've had to run the script a few times to get it to execute the skipped steps but it would be good to understand why certain steps are getting missed. Here's a link to my gist containing the script. Would appreciate any suggestions for improvements or explantations for the behaviour I'm seeing.
Things I have tried that havent resolved my issue:
Splitting the script into two smaller scripts
Erasing my mac and running the script again (done this several times)
Adding sleep 5 between each command
edit: this is how I'm running the script
sudo curl -Lks https://gist.githubusercontent.com/curtis-j-campbell/b695513a44393c3a5084c011c6d0c890/raw | /bin/bash
Thanks in advance
It appears that everything after brew install git is being echoed. That suggests that something in that command is copying its stdin to stdout, so it's processing the rest of the script. Change that line to
brew install git </dev/null
so it won't read the script as its stdin.
Also, you don't need to run curl under sudo. If you need privileges to install the program, you should run bash as the superuser, not curl.
curl -Lks https://gist.githubusercontent.com/curtis-j-campbell/b695513a44393c3a5084c011c6d0c890/raw | sudo /bin/bash

-bash: ghci: command not found (Haskell interactive shell, Haskell installation )

edit : I ended up upgrading to macOS Catalina yesterday and replacing bash with zsh. One thing that should be noted is that the stackcommand worked previously, but despite all the tinkering not ghci
After deleting all the files that had anything to do with Haskell, I retried running curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | sh
This second time there was an error with the command line tools so I had to install them manually with xcode-select --install. After rerunning the curl, I added the path to the environmental file to my zsh profile manually with :
. "$HOME/.ghcup/env"\
echo '. $HOME/.ghcup/env' >> "$HOME/.zshrc"
Here is the content of the env file :export PATH="$HOME/.cabal/bin:/Users/agnel/.ghcup/bin:$PATH"
Now everything seems to be working (I never reinstalled stack, but I think I might leave that to the side while I learn the basics of the language).
I installed the Haskell Platform yesterday but am having a hard time getting it to work correctly.
The firsts steps I did are:
curl -sSL https://get.haskellstack.org/ | sh
curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | sh
On step 1. the instructions said to append /Users/.../.local/bin the PATH variable (which I did in /etc/paths. On step 2, the script was supposed to pop up a dialog box (and didn't) when installing the necessary command line tools. It also said to rerun the script once complete (which I did). The script also said I should adjust my PATH variable, and source /Users/.../.ghcup/env in my shell configuration. It asked to this automatically but failed having not found the ~/.bashrc File. (I read that on Mac in contrary to linux, only .bash_profile is loaded upon opening of a terminal window so I adjusted the path variable there manually. I've spent forever messing around with the path variables and every time I try and run "$ ghci" I get the same -bash: ghci: command not found error message. If anyone has a solution to this problem I would be very grateful for an answer. If not, could someone with a working distribution of Haskell on their computer show me what their path variables look like?
Thanks!
A simple solution would just be to restart your terminal and you are good to go.
After installing the Haskell platform for the first time on a new mac with Catalina, I also got
~> ghci
zsh: command not found: ghci
What worked in my case was to use, instead of the plain ghci,
stack ghci
To get back the familiar behaviour, I created in my homedirectory a file named .zshrc containing
alias ghci='stack ghci'
If you open a new terminal, this file will automatically be executed.
I'd be interested to know if there is another solution.
Check if the ghcup command is working or not.
If not, make sure the .zshrc file has command for execution of ghcup. It should look something like this -
[ -f "/Users/myusername/.ghcup/env" ] && source "/Users/myusername/.ghcup/env" # ghcup-env
If the file exists, simply restarting terminal will work.
If it is still not working, set GHC as default using ghcup - follow this

How can I determine where an error message printed during shell startup comes from?

After uninstall Docker on Ubuntu, each time I start a bash shell window, it emits the following hint:
The program 'docker' is currently not installed. You can install it by typing:
sudo apt install docker.io
I have searched in .bashrc, .profile, .bash_profile, but didn't found any lines related to docker.
So, how can I get rid of those tips?
Run PS4=':${BASH_SOURCE}:$LINENO+' bash -x -l -i to log every command in your startup scripts, including which config file or script they came from. Search through that, and you'll find the individual command that's creating this error.
(Note that very new versions of bash ignore inherited values of PS4 when running as root for security reasons. But you're not using root as your primary account... right?)

OSX Terminal - application listed by 'which' does not run by default

I followed instructions on this page to change the profile of the Mac terminal when I'm running SSH. The short explanation is that it puts a wrapper script in /usr/local/bin that changes the colour then calls /usr/bin/ssh. When I call this script with the full path it works perfectly, but when I call 'ssh', it appears to use the regular application without the wrapper script.
When I call 'which ssh', the result is '/usr/local/bin/ssh'. My PATH variable is '/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Library/TeX/texbin', which looks fine for me. The wrapper script has executable permissions ('-rwxr-xr-x ').
What am I missing? Why would the regular ssh be called rather than than the wrapper script, given the 'which' command points to the one that I want?
You forgot to clear bash's program location cache.
hash -d ssh

Ruby 1.9.3 #OSX Lion and Cron

I installed Ruby 1.9.3p125 via this guide (up to point #5): LINK
Now I have this problem: my script works wonderfully from my command line, but if I execute it from Cron it seems to use a default environment and defaults to /usr/bin/ruby instead of mine (~/.rvm/rubies/ruby-1.9.3-p125/bin/ruby). What is the best way to have executed commands - manually or via cron - produce the same results?
PS: It seems to skip processing ~/.bash_login for example, where rvm is loaded into PATH
In your crontab line, you can source the .bash_login before you script is run.
source ~/.bash_login && <your original command here>
That way your script will have everything you have when you run it.
The usual way recommended to do this would be to put the full path to the executable in your crontab. E.g.
crontab should show:
/Users/Poochie/.rvm/rubies/ruby-1.9.3-p125/bin/ruby /full/path/to/script.rb
or whatever the full path is. It's much more robust than trying to get rvm loading, as here an rvm script is modifying your path for you. If you want to set it to whichever is the rvm default ruby (e.g. whatever was set by rvm use x.x.x --default), You can use: /Users/Poochie/.rvm/bin/ruby as the executable instead, e.g.:
/Users/Poochie/.rvm/bin/ruby /full/path/to/script.rb
I actually found this post which helped me a lot: LINK
I managed to run my script as I wanted but the questions is theoretically still open because the issue could still affect cron usage in general.

Resources