代碼: 選擇全部
mkdir -p ~/.local/bin/
echo "service postgresql start" >> ~/.local/bin/start_postgresql.sh
chmod +x ~/.local/bin/start_postgresql.sh
代碼: 選擇全部
calvin ALL=(root) NOPASSWD: /home/calvin/.local/bin/start_postgresql.sh
Now, click “Task Scheduler Library” on the left and then “Create Task…” on the right to create a new task you can configure to run your script with these steps:
Name the task anything you want, like “Start Postgres”
Under the “Triggers” tab, click “New…” to add a new trigger for this task
In the “Begin the task” dropdown select “At log on”
Select “Any user”
Under the “Actions” tab, click “New…” to add a new action for this task
Pick “Start a program” for the action type and then enter C:\Windows\System32\bash.exe as the program to run
Finally, as the last and most important step, at “Add arguments (optional)” set this argument string to run the command with: -c "sudo ~/.local/bin/start_postgresql.sh"