startup script editor adding question mark to filename

Post new topic   Reply to topic    DD-WRT Forum Forum Index -> General Questions
Author Message
troger
DD-WRT Novice


Joined: 03 Jan 2018
Posts: 4

PostPosted: Wed Sep 23, 2020 14:52    Post subject: startup script editor adding question mark to filename Reply with quote
I'm experiencing an odd issue with the GUI editor of the startup script. I have a short script that creates some directories, copies files from a USB drive into "/tmp", etc.

I recently upgraded my N66U; after the upgrade, I was modifying the script via the GUI editor to update some filenames. I noticed that things weren't working and boiled it down to an apparent issue with the way the GUI interprets the text pasted in, specifically line endings. I repro the issue by simply having this in the "commands" box then running the command from there with the "run commands" button:

Code:


mkdir /tmp/testing
cp /tmp/mnt/sda1/ssl/test.key /tmp/testing/key.pem



If I SSH into the box and look in "/tmp" I see "testing?", the second command if executed independently and assuming the directory is there will result with a filename of "key.pem?" What I believe is happening is that there are <CR><LF> line endings there and they're screwing things up.

This seems to be the case if I hand type these commands into the box, or paste them from an editor that does <LF> line endings.

Although when I look at the output of "nvram get rc_startup" if the script is saved, I don't see carriage returns:

Code:

nvram get rc_startup | grep -c '\r'
0


Firmware: DD-WRT v3.0-r44251 big (08/28/20)
I'm running the web interface GUI on Firefox on OSX.

I do have a workaround: I add "|ls" to every line. This presumably prevents the line ending <CR> in <CR><LF> from ending up in the filename. If that's the issue.

Code:


mkdir /tmp/testing|ls
cp /tmp/mnt/sda1/ssl/test.key /tmp/testing/key.pem|ls



I haven't really played with setting rc_startup directly in the console, since the GUI is a lot more convenient, but maybe that would bypass the problem.

Anyone know what's going on here?

Thanks in advance.
Sponsor
egc
DD-WRT Guru


Joined: 18 Mar 2014
Posts: 7236
Location: Netherlands

PostPosted: Wed Sep 23, 2020 15:05    Post subject: Reply with quote
You cannot run commands directly from the GUI, you have to use the CLI (command Line interface like telnet or putty)

Well you can run simple commands but not more complex ones

Well you can run more complex ones if you escape all special characters and take care of line endings

Bottom line do not use the GUI to directly run commands

_________________
Routers:Netgear R7800, R6400v1, R6400v2, Linksys EA8500, EA6900 (XvortexCFE), E2000 (converted WRT320N), WRT54GS v1.
WireGuard Documents & Guides:https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=327397
OpenVPN Documents & Guides: https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=327398
IPSET: https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=327261
Install guide R6400v2:http://forum.dd-wrt.com/phpBB2/viewtopic.php?t=316399
Install guide R7800: https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=320614
Forum Guide Lines (important read):https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=324087
troger
DD-WRT Novice


Joined: 03 Jan 2018
Posts: 4

PostPosted: Wed Sep 23, 2020 15:12    Post subject: Reply with quote
egc wrote:
You cannot run commands directly from the GUI, you have to use the CLI (command Line interface like telnet or putty)

Well you can run simple commands but not more complex ones

Well you can run more complex ones if you escape all special characters and take care of line endings

Bottom line do not use the GUI to directly run commands


So you're saying this has been always this way?

It's been a while since I updated any script but I could have sworn that I would paste the entire thing in there and hit "run commands" to make sure it works properly and only then save it. Admittedly, it's been a while, so I don't recall what my process was.

I haven't yet, but I should be able to save it, reboot and see if it did what I need to. I'm not sure if I did do that, I got myself running in circles last night on this issue.
kernel-panic69
DD-WRT Guru


Joined: 08 May 2018
Posts: 8051
Location: Texas, USA

PostPosted: Wed Sep 23, 2020 15:14    Post subject: Reply with quote
Proper syntax required to use the webUI commands entry box to execute them. Otherwise, it is only good for saving a custom startup, firewall, and additional custom script. I would have to do a little practice to see what the proper syntax is to enter your command(s).
_________________
Official Forum Rules, Guidelines & Helpful InformationFirmware FAQInstallation WikiWhere Do I Download Firmware?
DON'T use Chromium-based browsersRTFM/STFW TL;DR is NOT an excuse. • Why Should I Care What Color the Bikeshed Is?
Please DO NOT PM me with questions; Ask in the forum. ---------------------- Linux User #377467 counter.li.org / linuxcounter.net
egc
DD-WRT Guru


Joined: 18 Mar 2014
Posts: 7236
Location: Netherlands

PostPosted: Wed Sep 23, 2020 15:29    Post subject: Reply with quote
troger wrote:
egc wrote:
You cannot run commands directly from the GUI, you have to use the CLI (command Line interface like telnet or putty)

Well you can run simple commands but not more complex ones

Well you can run more complex ones if you escape all special characters and take care of line endings

Bottom line do not use the GUI to directly run commands


So you're saying this has been always this way?

It's been a while since I updated any script but I could have sworn that I would paste the entire thing in there and hit "run commands" to make sure it works properly and only then save it. Admittedly, it's been a while, so I don't recall what my process was.

I haven't yet, but I should be able to save it, reboot and see if it did what I need to. I'm not sure if I did do that, I got myself running in circles last night on this issue.


Yes that has always been the case, really do not use the GUI to directly run commands unless really simple ones (you can save the script and run the script from the GUI that is a simple command).

Just use something like putty like most of us do Smile

_________________
Routers:Netgear R7800, R6400v1, R6400v2, Linksys EA8500, EA6900 (XvortexCFE), E2000 (converted WRT320N), WRT54GS v1.
WireGuard Documents & Guides:https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=327397
OpenVPN Documents & Guides: https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=327398
IPSET: https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=327261
Install guide R6400v2:http://forum.dd-wrt.com/phpBB2/viewtopic.php?t=316399
Install guide R7800: https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=320614
Forum Guide Lines (important read):https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=324087
troger
DD-WRT Novice


Joined: 03 Jan 2018
Posts: 4

PostPosted: Wed Sep 23, 2020 15:48    Post subject: Reply with quote
egc wrote:
troger wrote:
egc wrote:
You cannot run commands directly from the GUI, you have to use the CLI (command Line interface like telnet or putty)

Well you can run simple commands but not more complex ones

Well you can run more complex ones if you escape all special characters and take care of line endings

Bottom line do not use the GUI to directly run commands


So you're saying this has been always this way?

It's been a while since I updated any script but I could have sworn that I would paste the entire thing in there and hit "run commands" to make sure it works properly and only then save it. Admittedly, it's been a while, so I don't recall what my process was.

I haven't yet, but I should be able to save it, reboot and see if it did what I need to. I'm not sure if I did do that, I got myself running in circles last night on this issue.


Yes that has always been the case, really do not use the GUI to directly run commands unless really simple ones (you can save the script and run the script from the GUI that is a simple command).

Just use something like putty like most of us do Smile


Ok, I just re-tested my scripts by pasting them, saving and rebooting....and it works just fine. Rolling Eyes

I guess I should avoid messing around with this late at night.

Like I said above, I could have sworn that I would use "run commands" to dry run the script before deploying it. I guess I'm misremembering.

What could have happened is that with the upgrade I just ran, it appears that the startup script (rc_startup) now runs much earlier than before. I need a USB drive mounted for this particular one to work. This might have led me down this path where I was "dry running" the script and went down this rabbit hole.

Anyway that's way too much info already.

----

I moved the script to "rc_usb" since it's dependent on the USB. It appears to be a new feature. (It's been a while since I upgraded.) Perhaps I should just use a delay in the startup script....presumably rc_usb is called each time any USB is mounted, which could be an issue. (I restart httpd in this script.)

Also, silver lining: although kludgy af, putting that pipe to ls at the end of each line in the window gets rid of at least this limitation if you're hell bent on working from the GUI.
egc
DD-WRT Guru


Joined: 18 Mar 2014
Posts: 7236
Location: Netherlands

PostPosted: Wed Sep 23, 2020 15:57    Post subject: Reply with quote
The problem is not the startup script running earlier but the USB mounting is slow, I use a script to wait for the usb to come up and then executing the startup script, but now you have the new usb startup, I have not tested that yet.

I begin my startup script with:

Code:
#instead of sleep check if USB is mounted by sleeping until file: usb-is-mounted is found
(i=0
until [[ -f /jffs/usb-is-mounted ]]; do
   sleep 1
   i=$((i+1))
   if [[ $i -gt 35 ]]; then
      logger "No USB mounted"
      touch "/jffs/usb-is-mounted"
      exit
   fi
   done
logger "USB $i seconds before mounted")


This checks the existence of a file on /jffs (and it will make that file if not present)

but starting with sleep 30 also works.
On my R6400 it takes about 8 seconds before the USB stick is mounted (it writes the mount time to syslog)

_________________
Routers:Netgear R7800, R6400v1, R6400v2, Linksys EA8500, EA6900 (XvortexCFE), E2000 (converted WRT320N), WRT54GS v1.
WireGuard Documents & Guides:https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=327397
OpenVPN Documents & Guides: https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=327398
IPSET: https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=327261
Install guide R6400v2:http://forum.dd-wrt.com/phpBB2/viewtopic.php?t=316399
Install guide R7800: https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=320614
Forum Guide Lines (important read):https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=324087
troger
DD-WRT Novice


Joined: 03 Jan 2018
Posts: 4

PostPosted: Wed Sep 23, 2020 16:22    Post subject: Reply with quote
egc wrote:
The problem is not the startup script running earlier but the USB mounting is slow, I use a script to wait for the usb to come up and then executing the startup script, but now you have the new usb startup, I have not tested that yet.

I begin my startup script with:

Code:
#instead of sleep check if USB is mounted by sleeping until file: usb-is-mounted is found
(i=0
until [[ -f /jffs/usb-is-mounted ]]; do
   sleep 1
   i=$((i+1))
   if [[ $i -gt 35 ]]; then
      logger "No USB mounted"
      touch "/jffs/usb-is-mounted"
      exit
   fi
   done
logger "USB $i seconds before mounted")


This checks the existence of a file on /jffs (and it will make that file if not present)

but starting with sleep 30 also works.
On my R6400 it takes about 8 seconds before the USB stick is mounted (it writes the mount time to syslog)


Yeah, something has changed since the last version I ran, but the startup script worked 100% reliably without checking for the mount or any delay. It was already mounted by the time it ran.

I'm not sure I'm curious enough to go through 2 years of changelists to find out. haha Shocked

There's always something that gets me when I upgrade. It's the nature of this beast.
Display posts from previous:    Page 1 of 1
Post new topic   Reply to topic    DD-WRT Forum Forum Index -> General Questions All times are GMT

Navigation

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum