Custom script not running from SSH (Archer C6 v3.20)

Hey there, I'm a newbie at this thing, so please forgive me for my lack of knowledge... So I recently made a custom script to turn my router's LEDs off and on, and the way I planned to do it was to make two UCI scripts first and then run the scripts from the Scheduler crontab. I've already made sure the scripts are executable (I guess, I mean the text on the script files turned green after I chmod +x ed it) but whenever I try to execute it, I get greeted with this message saying, "-ash: ./led_schedule_off.sh: not found." Did I do something wrong in the scripts that's causing this error? TYIA

The scripts I wrote,
1)led_schedule_off.sh

#!/bin/sh

# Turn off LEDs
uci set system.led_wan.trigger='none'
uci set system.led_lan.trigger='none'
uci set system.cfg058bba.trigger='none'
uci set system.cfg068bba.trigger='none'
uci set system.cfg078bba.trigger='none'
uci commit

2)led_schedule_on.sh

#!/bin/sh

# Turn on LEDs
uci set system.led_wan.trigger='netdev'
uci set system.led_wan.dev='wan'
uci add_list system.led_wan.mode='tx'
uci add_list system.led_wan.mode='rx'
uci set system.led_lan.trigger='default-on'
uci set system.cfg058bba.trigger='default-on'
uci set system.cfg068bba.trigger='default-on'
uci set system.cfg078bba.trigger='heartbeat'
uci commit

Do they have execute permissoins?

chmod +x led*

Then try running it again.

Yes, the user has done so.

Ah... thanks. I missed that line.

Would be better if you posted the output of: ls -la /etc/led_shedule/ so we could see user/group/permissions better.

here it is:

Hey guys! A quick follow up... I actually managed to run the script by typing sh led_schedule_off.sh

BUT now I'm facing an even weirder problem where the script actually executes and all but the actual LEDs on my router are not turning off as expected. Now the way I figured out the script was working was I went to System>Led Configuration tab and saw the default state of all LEDs showing "none" and whenever I try to hit "Save & Apply" it hits me back saying "There are no changes to apply." Now initially, I made sure to include uci commit at the end of my scripts that should've saved and applied... so did I miss some other codes that I should've included? Thank You For Your TIme.

Yeah, sorry, mistyped the command, but looks like you've fixed it.

Have you made sure that the line-breaks in your file are not Windows, but Linux ones?

Hey folks! This is going to be my last follow-up on this topic. I finally managed to run the scripts, and it worked as intended! All this time, all I needed was to restart the LEDs after uci committing :man_facepalming:. But it's finally working, and now all I need to do is wait to see if the crontab works. Here are the final codes after a little bit of tweaking,

1)led_schedule_off.sh:

#!/bin/sh

uci set system.led_wan.trigger='none'
uci set system.led_wan.default='0'
uci set system.led_lan.trigger='none'
uci set system.led_lan.default='0'
uci set system.cfg058bba.trigger='none'
uci set system.cfg058bba.default='0'
uci set system.cfg068bba.trigger='none'
uci set system.cfg068bba.default='0'
uci set system.cfg078bba.trigger='none'
uci set system.cfg078bba.default='0'
uci commit

/etc/init.d/led restart

2)led_schedule_on.sh:

#!/bin/sh

uci set system.led_wan.trigger='netdev'
uci set system.led_wan.dev='wan'
uci add_list system.led_wan.mode='tx'
uci add_list system.led_wan.mode='rx'
uci set system.led_lan.trigger='default-on'
uci set system.cfg058bba.trigger='default-on'
uci set system.cfg068bba.trigger='default-on'
uci set system.cfg078bba.trigger='heartbeat'
uci commit

/etc/init.d/led restart

I wish I could change the title of the topic to "custom LED scheduling script not running (TP Link Archer C6 v3.20)" so people can find the post easily. But I can't. Anyway, dear admins you can close this topic off. Thank you all for your time!

CladFish,

The topic will be closed automatically if you mark it as solved:

If your problem is solved, please consider marking this topic as [Solved]. See How to mark a topic as [Solved] for a short how-to.
Thanks! :slight_smile:

oh okay... got it, Thanks!

Besides that's cool that you've figured out how to trigger your LED i think I'm not alone thats puzzling why the shell was not able to execute the script.

1 Like

wait, so my command was right? Damn, now I'm also confused as to why it worked with sh led_schedule_off.sh and not ./led_schedule_off.sh. is there a way to see the logs that can help us see why it showed "not found?"

The reason I can think off is if there is no shebang.

But there is #!/bin/sh

I would double check if there are no Windows style line feeds in those lines, maybe recreate with nano or vi on the router.

1 Like

No. It's not required... But I assume its only valid for scripts in the same language as the current shell...

root@cpe:~# vim /tmp/test.sh
root@cpe:~# cat /tmp/test.sh

test 1 && echo "yeah!"
echo "nope. you don't even need a shebang!"

exit 1

root@cpe:~# chmod +x /tmp/test.sh
root@cpe:~# /tmp/test.sh
yeah!
nope. you don't even need a shebang!
2 Likes

I was curious as to whether it was line endings, so I ran your test with dos (CRLF) and mac (CR), too. They both ran, albeit the mac line endings mashed everything onto one line and the script output was, uh, not great.

I was surprised to see that Busybox ash handles dos line endings without a whimper, as Python and bash are very sensitive about such things.

$ bash ./test.sh
./test.sh: line 1: $'\r': command not found
1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.