back

by tapper·3y ago·view on hn ↗
I love what it can do and at the same time it's scary. I asked it to write me a script to turn the wifi on my openwrt router at 9.30 pm and back on again at 6 am. It even commented the code.

Hi I want you to write me a script to ron on my OpenWrt router. I want to shut down my wifi at 9.30 PM and then turn it back on at 6 AM

Sure, here is a script that you can use to shut down your WiFi at 9:30 PM and turn it back on at 6 AM: Copy code #!/bin/sh

# This script will shut down the WiFi at 9:30 PM and turn it back on at 6 AM

# Check the current time CURRENT_TIME=$(date +%H:%M)

# Shut down the WiFi at 9:30 PM if [ "$CURRENT_TIME" = "21:30" ]; then wifi down fi

# Turn the WiFi back on at 6 AM if [ "$CURRENT_TIME" = "06:00" ]; then wifi up fi To use this script, you will need to save it to your OpenWrt router and make it executable. Here's how you can do that: 1. SSH into your OpenWrt router using a command like `ssh root@192.168.1.1` (replace `192.168.1.1` with the IP address of your router) 2. Create a new file called `wifi-scheduler.sh` using the `nano` text editor: `nano wifi-scheduler.sh` 3. Paste the script into the file and save it: • Press `CTRL+X` to exit the text editor • Press `Y` to save the file • Press `Enter` to confirm the file name 4. Make the script executable: `chmod +x wifi-scheduler.sh` To run the script automatically at the specified times, you can add it to your router's `crontab` (short for "cron table"). Here's how you can do that: 1. Edit the `crontab` using the `crontab -e` command 2. Add the following lines to the `crontab` to run the script at 9:30 PM and 6 AM: Copy code 30 21 * * * /root/wifi-scheduler.sh 00 06 * * * /root/wifi-scheduler.sh 3. Save the `crontab` and exit the text editor That's it! Your WiFi should now automatically shut down at 9:30 PM and turn back on at 6 AM.