0

I made a script (name of the file is update) to update and upgrade in one command. All it is is:

#! /bin/bash
sudo /usr/bin/apt-get update
sudo /usr/bin/apt-get upgrade

I used the full paths, as well putting this in its own directory, /home/user_name/custom_scripts. I also made sure to designate this directory as root, the permissions are listed as

drwxr-xr-x. 2 root root 4096 Aug 23 00:12 custom_scripts

and the executable script is:

-rwx------. 1 root root 73 Aug 23 00:12 update

I edited my path to look like this /home/user_name/custom_scripts:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games yet for some reason this won't execute if I type sudo update. The weirdest thing is if I just try update, I get a permission denied exception.

I'm not really sure what's wrong.

Astrum
  • 431

2 Answers2

0

It sounds like you want to have it just run using Cron. Have a look at What are the runtime permissions of a cron job? but essentially just copy the script to one of the cron folder such as /etc/cron.daily

I would also recommend removing the sudo as its redundant. Cron will run it as root.

Laywah
  • 66
  • Should I keep the file permissions the same? Or does it not matter since /etc/cron.daily is only open for root? – Astrum Aug 23 '17 at 06:05
  • root needs execute permissions that's about it. you can leave them as they are though – Laywah Aug 24 '17 at 03:30
0

I think that you have changed the $PATH variable for user_name but not for sudo.

I'm surprised about the permission denied, if you have sudo at the beginning of the command, it should ask you for the password when you run it manually.

For what you are trying to do, I think an alias would be more suitable, check https://askubuntu.com/questions/17536/how-do-i-create-a-permanent-bash-alias

Katu
  • 1,284
  • 9
  • 10