What's new

can not remove file from either /tmp/home/root or /jffs

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

Gravityz

Senior Member
i was playing around with reading and writing the dhcp list and i succeeded.
i now however want to delete the created dhcplist.txt file but i get the error, no such file or directory.
it is clearly visible in both winscp and also form the command line.

it looks like the file is created but still in some kind of locked mode.
any idea how to force remove it?

i used the command nvram get dhcp_staticlist >dhcplist.txt to create it
i used the following to write it

nvram set dhcp_staticlist="dhcplist.txt"
nvram commit
reboot

is there perhaps some kind of process which is hanging? how can i find out
 

Attachments

  • error1.jpg
    error1.jpg
    79.1 KB · Views: 153
  • error2.jpg
    error2.jpg
    133.6 KB · Views: 169
1. You've got a non-visable character in the filename which is why rm can't find the file. Use a GUI file manger to delete it or use a wildcard (e.g. rm *dhcp*).

2. nvram set dhcp_staticlist="dhcplist.txt" is not the correct way to set that variable.
 
Thanks Colin, rm*dhcp* did the trick (i feel so stupid)
strange thing is that i could no delete it from winscp either

indeed that nvram set command is not right and probably caused it

i remembered that i created 2 scripts for this some time ago but laizy as i am i forgot about them

read script
nvram get dhcp_staticlist > dhcplist.txt

write script
Code:
nvram set dhcp_staticlist="$(cat dhcplist.txt)"
nvram commit

i even have a sort script but since this script was for a fork version i was afraid to use it.
instead i sorted the file by hand

sorting script
Code:
nvram get dhcp_staticlist | sed 's/</\n/g' | grep ":" | awk -F">" '{ print $2">"$1">"$3; }' | \
sort -t . -k 1,1n -k 2,2n -k 3,3n -k 4,4n | awk -F">" '{ print $2">"$1">"$3; }' | \
sed 's/^/</g' | tr -d '\n' | sed 's/^/nvram set dhcp_staticlist="/' | sed 's/$/"\n/' | \
tee /tmp/dhcp_list_sorted_tmp.sh
 
Being a fan of loop scripts, I use similar to these making nvram settings more human readable and easier to manipulate.
Code:
a="a" ; n=2 ; list=$(nvram get dhcp_staticlist)
until [ "$a" == "" ] ; do a=`echo $list | cut -f$n -d"<"` ; n=$(($n+1)) ;  [ "$a" == "" ] && break ; echo "<$a"; done > /tmp/dhcp_staticlist.txt

In the resulting test file, this puts each entry on a separate line.
The file can then be hand sorted and manipulated or I can pipe this through sort before writing it to the text file.

To put my sorted or manipulated text file back into nvram this one liner works well.
Code:
for i in `grep . /tmp/dhcp_staticlist.txt` ; do staticlist=$staticlist$i ; done; nvram set dhcp_staticlist="$staticlist" ; nvram commit
You can test this by substituting the command nvram for echo . Then read the output on the terminal before committing the changes with the original one-liner.
I keep several similar aliases and functions in /opt/etc/profile to make quick work of maintenance tasks.
 
thanks.
tried the reading part and it works.

i use notepad2-mod to do the editing and i noticed that the last entry is not accepted right.
i think this is because encoding was on ansi and line ending on windows
changed it to UTF-8 and unix

the writing script can be executed from /jffs/scripts and reads the dhcp_staticlist.txt(which i sorted manually) from /tmp right?

for my old script i did not use absolute paths so this works better
thanks
 
Last edited:
The output of the read script would be null terminated without a [LF] or [LF][CR]

The editer is probably the difference then.
I edit using vi natively on the router itself.
This saves me the steps of moving files back and forth between 2 boxes.

I don't use notepad2-mod. If I'm creating a file on windows destined for a linux box I use notepadd++. And I make sure it is set appropriately
to only have a [LF] at the end insted of [LF][CR] . While editing from linux and seeing ^M at the end of a line is a pet peeve for me. :)
 
the notepads are probably the same

the reason i use notepad2-mod is i do everything from winscp.

i do not work a lot with vi(only from the commandline if nothing else works because i tend to forget how to insert and copy/paste stuff)

i noticed that when you use the new file and write it to nvram the router still keeps the assigned icons so that is nice.
 
The output of the read script would be null terminated without a [LF] or [LF][CR]
Technically, I guess it would be [CR][LF] to get the print head started back to home before moving the output up and beginning to print again.
But I think you understood.
 
Funny, And I have the opposite problem that I'm using "vi" commands while sitting at a windows box and wonderinging why it's not working.

I'll have to try moving text type files I've created this way from my router to something with windows. Letting me see the effects you described on the last line.
 
Being a fan of loop scripts, I use similar to these making nvram settings more human readable and easier to manipulate.
Code:
a="a" ; n=2 ; list=$(nvram get dhcp_staticlist)
until [ "$a" == "" ] ; do a=`echo $list | cut -f$n -d"<"` ; n=$(($n+1)) ;  [ "$a" == "" ] && break ; echo "<$a"; done > /tmp/dhcp_staticlist.txt

In the resulting test file, this puts each entry on a separate line.
The file can then be hand sorted and manipulated or I can pipe this through sort before writing it to the text file.

To put my sorted or manipulated text file back into nvram this one liner works well.
Code:
for i in `grep . /tmp/dhcp_staticlist.txt` ; do staticlist=$staticlist$i ; done; nvram set dhcp_staticlist="$staticlist" ; nvram commit
You can test this by substituting the command nvram for echo . Then read the output on the terminal before committing the changes with the original one-liner.
I keep several similar aliases and functions in /opt/etc/profile to make quick work of maintenance tasks.

Well i upgraded the firmware so this was the chance to test both scripts.

They work really great, both the reading script as well as the writing script.

this gave me the courage to renumber the complete DHCP list.

thanks again
 

Gravityz,​

Phew ! You are Welcome.
I had wondered how well it would work for you. Was this used on your RT-AX88U, RT-AC66U or another not listed ?
I'd forgotten to mention this was from my RT-N66U with current stock firmware.
And may have needed some tweaking if the format had changed.
Apparently it hasn't changed and could be safe for other models.
 
yes i used it on my stock firmware RT-AX88U
it does not require any reboot
as soon as i execute the write script and go to lan-dhcpserver-dhcplist everything is there.

the trick is to edit the list using a unix formatted editor(as mentioned i am not a fan of vi because i hardly use it)
i use notepad2 but then you need to select UTF-* encoding and unix line endings(LF)
the windows line ending(CR+LF) was my cullprit
 
Similar threads
Thread starter Title Forum Replies Date
F Why doesn't ASUS remove useless features? ASUSWRT - Official 15

Similar threads

Latest threads

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top