Hello guys i'm learning about linux for myself and i wrote a program sample by python as below with filename as "sample_login" at "/home/user/Desktop/sample_login"
ID = Input("ID: ")
print (ID)
pw = Input("PW: ")
print (pw)
Now i want to make a shell script that could change to this program directory and run my program and input id and pw automatically to program console after reboot then how could i do it?i mean perform command as below
cd /home/user/Desktop
./sample_login
#wait ID:
#input user_id
...
Thank you guys so much
In order to run a script at boot up, you can use systemd service files.
sample.service:
[Unit]
Description=sample service
[Service]
User=johndoe
WorkingDirectory=/path/to/working_dir/
ExecStart=/path/to/working_dir/your_script
Restart=always
[Install]
WantedBy=multi-user.target
You just need to move this file to /etc/systemd/system/.
and enable it with systemctl enable sample.service
so it starts at bootup. Instead of expecting input, you could accept command line parameters that's a bit easier to handle in automated scripts.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.