Man vs. Machine

This linux bash script was generated by an Artificial Intelligence (AI) application called ChatGPT. The script was generated in response to this text: “Write a bash script that prompts for the action and service, and then runs the systemctl command using this action/service couplet.” It took ChatGTP a minute or so to produce the script.


#!/bin/bash
# Prompt the user for the action
echo "Enter the action you want to perform (start, stop, restart, status):"
read action
# Prompt the user for the service
echo "Enter the name of the service you want to control:"
read service
# Perform the requested action on the specified service
if [ "$action" = "start" ]; then
sudo systemctl start "$service"
elif [ "$action" = "stop" ]; then
sudo systemctl stop "$service"
elif [ "$action" = "restart" ]; then
sudo systemctl restart "$service"
elif [ "$action" = "status" ]; then
sudo systemctl status "$service"
else
echo "Invalid action"
fi

Here is a script I wrote a while back that does the same thing. It took me about 30 minutes to produce and test this script.


#!/bin/bash
echo "Service Controller"
echo " Commands: start stop restart status quit"
echo " or one of the many more Linux systemctl commands"
echo " Service: one of the many Linux Daemons ;-)"
echo " "
byebye="quit"
while :
do
echo -n "Enter Command: "
read cmd
if [[ $cmd != $byebye ]]
then
echo -n "Enter Service: "
read svc
sudo systemctl $cmd $svc
else
echo "Bye"
exit 0
fi
done