autoshutdown?? [Solved]

Post here if you are a new Porteus member and you're looking for some help.
User avatar
Ed_P
Contributor
Contributor
Posts: 8360
Joined: 06 Feb 2013, 22:12
Distribution: Cinnamon 5.01 ISO
Location: Western NY, USA

autoshutdown?? [Solved]

Post#1 by Ed_P » 20 Mar 2016, 05:26

There is a /.config/autostart folder for scripts that automatically run when booting. Is there a similar idea for scripts to run when shutting down?

A Chrome module I am trying creates a very large cache folder which gets saved in my save.dat file. I would like to purge it when shutting down rather than save it.
Last edited by Ed_P on 23 Mar 2016, 18:24, edited 1 time in total.
Ed

Bogomips
Full of knowledge
Full of knowledge
Posts: 2564
Joined: 25 Jun 2014, 15:21
Distribution: 3.2.2 Cinnamon & KDE5
Location: London

Re: autoshutdown??

Post#2 by Bogomips » 20 Mar 2016, 12:24

rc.local_shutdown, but not sure if executed before saving changes. :unknown:
Linux porteus 4.4.0-porteus #3 SMP PREEMPT Sat Jan 23 07:01:55 UTC 2016 i686 AMD Sempron(tm) 140 Processor AuthenticAMD GNU/Linux
NVIDIA Corporation C61 [GeForce 6150SE nForce 430] (rev a2) MemTotal: 901760 kB MemFree: 66752 kB

User avatar
Ed_P
Contributor
Contributor
Posts: 8360
Joined: 06 Feb 2013, 22:12
Distribution: Cinnamon 5.01 ISO
Location: Western NY, USA

Re: autoshutdown??

Post#3 by Ed_P » 20 Mar 2016, 21:11

Ok Bogomips that is where I have it but it isn't working.

rc.local_shutdown

Code: Select all

#!/bin/sh
#
# rc.local_shutdown
#
# This script is executed at shutdown (rc0) and reboot (rc6).
# You need to make it executable before using.
#
# Example:
# /etc/rc.d/rc.samba stop
/home/guest/chromecache.sh
chromecache.sh

Code: Select all

#!/bin/sh

if [ -d "/home/guest/.cache/google-chrome/Default/Cache/" ]; then
  rm /home/guest/.cache/google-chrome/Default/Cache/*
  echo "Chrome cache purged."
else
  echo "No Chrome cache."
fi
No echos when shutting down. And the script works in terminal mode. I'm missing something.
Ed

tome
Contributor
Contributor
Posts: 676
Joined: 26 Jun 2013, 14:03
Distribution: x64 Openbox
Location: Russia is causing the immense damage to humanity
Contact:

Re: autoshutdown??

Post#4 by tome » 20 Mar 2016, 21:42

I think you can replace cache directory with symlink, for example symlink to /mnt/sda4/DefaultCache2 or to /mnt/ramd/cache (mkdir -p /mnt/ramd
mount ramdisk /mnt/ramd -t tmpfs -o size=105M
mkdir -p /mnt/ramd/cache
chown guest:guest /mnt/ramd/cache)

See at '/etc/changes-exit.conf' also.:good:
You have mind and feelings. Be wise and clever.

User avatar
Ed_P
Contributor
Contributor
Posts: 8360
Joined: 06 Feb 2013, 22:12
Distribution: Cinnamon 5.01 ISO
Location: Western NY, USA

Re: autoshutdown??

Post#5 by Ed_P » 20 Mar 2016, 22:03

Well I found the problem with rc.local_shutdown, it needed to be made executable!!

http://forum.porteus.org/viewtopic.php? ... 696#p32711

Your symlink idea is interesting tome. I was thinking of finding a way to redirect the chrome cache to the /tmp/ directory to solve the savedata space issue. And doing that would eliminate the concern of hundreds of thousands of .wh. files from all the cache deletes.
Ed

Bogomips
Full of knowledge
Full of knowledge
Posts: 2564
Joined: 25 Jun 2014, 15:21
Distribution: 3.2.2 Cinnamon & KDE5
Location: London

Re: autoshutdown??

Post#6 by Bogomips » 20 Mar 2016, 23:08

@Ed Running in ram, and having not that much ram at my disposal, done more or less what you have in mind, within the guiexec script, for the PaleMoon cache:

Code: Select all

mkdir .cache/'moonchild productions'
sudo mount --bind /mnt/sda4/PaleMoon/moonchild .cache/'moonchild productions'
:wink:
Linux porteus 4.4.0-porteus #3 SMP PREEMPT Sat Jan 23 07:01:55 UTC 2016 i686 AMD Sempron(tm) 140 Processor AuthenticAMD GNU/Linux
NVIDIA Corporation C61 [GeForce 6150SE nForce 430] (rev a2) MemTotal: 901760 kB MemFree: 66752 kB

User avatar
Ed_P
Contributor
Contributor
Posts: 8360
Joined: 06 Feb 2013, 22:12
Distribution: Cinnamon 5.01 ISO
Location: Western NY, USA

Re: autoshutdown??

Post#7 by Ed_P » 21 Mar 2016, 16:50

hmmmm Not working for me.

Code: Select all

guest@porteus:~$ chrome.sh
mkdir: cannot create directory ‘/tmp/google-chrome/Cache/’: No such file or directory
sudo: invalid option -- '-'
usage: sudo [-D level] -h | -K | -k | -V
usage: sudo -v [-AknS] [-D level] [-g groupname|#gid] [-p prompt] [-u user
            name|#uid]
usage: sudo -l[l] [-AknS] [-D level] [-g groupname|#gid] [-p prompt] [-U user
            name] [-u user name|#uid] [-g groupname|#gid] [command]
usage: sudo [-AbEHknPS] [-C fd] [-D level] [-g groupname|#gid] [-p prompt] [-u
            user name|#uid] [-g groupname|#gid] [VAR=value] [-i|-s] [<command>]
usage: sudo -e [-AknS] [-C fd] [-D level] [-g groupname|#gid] [-p prompt] [-u
            user name|#uid] file ...
The part of the code failing:

Code: Select all

if [ ! -d /tmp/google-chrome/Cache ]; then
   mkdir  /tmp/google-chrome
   mkdir  /tmp/google-chrome/Cache
   sudo mount --bind /tmp/google-chrome/Cache  /home/guest/.cache/google-chrome/Default/Cache
fi 
And

Code: Select all

guest@porteus:~$ ls /tmp
qtsingleapp-qlippe-2dfb-3e8=  qtsingleapp-qlippe-2dfb-3e8-lockfile
guest@porteus:~$ 
But

Code: Select all

guest@porteus:~$ mkdir  /tmp/google-chrome
guest@porteus:~$ mkdir  /tmp/google-chrome/Cache
guest@porteus:~$ ls /tmp
google-chrome/                qtsingleapp-qlippe-2dfb-3e8-lockfile
qtsingleapp-qlippe-2dfb-3e8=
guest@porteus:~$ ls /tmp/google*
Cache/
guest@porteus:~$ sudo mount --bind /tmp/google-chrome/Cache  /home/guest/.cache/google-chrome/Default/Cache
Password:
mount: mount point /home/guest/.cache/google-chrome/Default/Cache does not exist
guest@porteus:~$ 
The last error being understandable since chrome hasn't been run yet.
Ed

Bogomips
Full of knowledge
Full of knowledge
Posts: 2564
Joined: 25 Jun 2014, 15:21
Distribution: 3.2.2 Cinnamon & KDE5
Location: London

Re: autoshutdown??

Post#8 by Bogomips » 21 Mar 2016, 19:58

Ed_P wrote:

Code: Select all

if [ ! -d /tmp/google-chrome/Cache ]; then
   mkdir  /tmp/google-chrome
   mkdir  /tmp/google-chrome/Cache
   sudo mount --bind /tmp/google-chrome/Cache  /home/guest/.cache/google-chrome/Default/Cache
fi 
Replace with:

Code: Select all

set -x;  # Diagnostic output
if [ ! -d /tmp/google-chrome/Cache ]; then
   mkdir  -p  /tmp/google-chrome/Cache;  # Less chance of invisible chars creeping in
   sudo mount --bind /tmp/google-chrome/Cache  /home/guest/.cache/google-chrome/Default/Cache
fi 
And let's see what we get.
Linux porteus 4.4.0-porteus #3 SMP PREEMPT Sat Jan 23 07:01:55 UTC 2016 i686 AMD Sempron(tm) 140 Processor AuthenticAMD GNU/Linux
NVIDIA Corporation C61 [GeForce 6150SE nForce 430] (rev a2) MemTotal: 901760 kB MemFree: 66752 kB

User avatar
Ed_P
Contributor
Contributor
Posts: 8360
Joined: 06 Feb 2013, 22:12
Distribution: Cinnamon 5.01 ISO
Location: Western NY, USA

Re: autoshutdown??

Post#9 by Ed_P » 21 Mar 2016, 20:48

Bogomips wrote:And let's see what we get.
The results make no sense at all.

Code: Select all

guest@porteus:~$ ls /tmp
qtsingleapp-qlippe-2dfb-3e8=  qtsingleapp-qlippe-2dfb-3e8-lockfile
guest@porteus:~$ chrome.sh
+ '[' '!' -d /tmp/google-chrome/Cache/ ']'
+ mkdir -p /tmp/google-chrome/Cache/
+ sudo --bind /tmp/google-chrome/Cache /home/guest/.cache/google-chrome/Default/Cache
sudo: invalid option -- '-'
usage: sudo [-D level] -h | -K | -k | -V
usage: sudo -v [-AknS] [-D level] [-g groupname|#gid] [-p prompt] [-u user
            name|#uid]
usage: sudo -l[l] [-AknS] [-D level] [-g groupname|#gid] [-p prompt] [-U user
            name] [-u user name|#uid] [-g groupname|#gid] [command]
usage: sudo [-AbEHknPS] [-C fd] [-D level] [-g groupname|#gid] [-p prompt] [-u
            user name|#uid] [-g groupname|#gid] [VAR=value] [-i|-s] [<command>]
usage: sudo -e [-AknS] [-C fd] [-D level] [-g groupname|#gid] [-p prompt] [-u
            user name|#uid] file ...
+ read
+ google-chrome-stable 'https://us.forgeofempires.com/page/ '
^C
guest@porteus:~$ ls /tmp
google-chrome/                qtsingleapp-qlippe-2dfb-3e8-lockfile
qtsingleapp-qlippe-2dfb-3e8=
guest@porteus:~$ 
I tried the mkdir -p option initially and had the same error, so I changed it to individual mkdirs. Now it works?? What does the set do? I have never seen it before.

Code: Select all

set -x;  # Diagnostic output!!
if [ ! -d /tmp/google-chrome/Cache/ ]; then
   mkdir -p /tmp/google-chrome/Cache/
   sudo --bind /tmp/google-chrome/Cache   /home/guest/.cache/google-chrome/Default/Cache
fi
Ed

Bogomips
Full of knowledge
Full of knowledge
Posts: 2564
Joined: 25 Jun 2014, 15:21
Distribution: 3.2.2 Cinnamon & KDE5
Location: London

Re: autoshutdown??

Post#10 by Bogomips » 21 Mar 2016, 21:49

sudo mount -- bind 8)

-x shows step by step progress, a blow by blow account :)

btw your sudo ok? sudoers set and you don't have to submit pw?

Search for set in http://man.cx/bash
Linux porteus 4.4.0-porteus #3 SMP PREEMPT Sat Jan 23 07:01:55 UTC 2016 i686 AMD Sempron(tm) 140 Processor AuthenticAMD GNU/Linux
NVIDIA Corporation C61 [GeForce 6150SE nForce 430] (rev a2) MemTotal: 901760 kB MemFree: 66752 kB

User avatar
Ed_P
Contributor
Contributor
Posts: 8360
Joined: 06 Feb 2013, 22:12
Distribution: Cinnamon 5.01 ISO
Location: Western NY, USA

Re: autoshutdown??

Post#11 by Ed_P » 21 Mar 2016, 23:29

Bogomips wrote:sudo mount -- bind 8)
:shock: I had mount originally. What the heck??

Will retest and get back to you. :(
Ed

User avatar
Ed_P
Contributor
Contributor
Posts: 8360
Joined: 06 Feb 2013, 22:12
Distribution: Cinnamon 5.01 ISO
Location: Western NY, USA

Re: autoshutdown??

Post#12 by Ed_P » 22 Mar 2016, 05:31

Ok, it seems to be working.

Code: Select all

guest@porteus:~$ chrome.sh
/mnt/sda5/porteus3.0/Modules/zchrome.xzm

Chrome ready to run. Press Enter when done using it.
+ '[' '!' -d /tmp/google-chrome/Cache/ ']'
+ mkdir -p /tmp/google-chrome/Cache/
+ sudo mount --bind /tmp/google-chrome/Cache /home/guest/.cache/google-chrome/Default/Cache
Password:Password:
mount: mount point /home/guest/.cache/google-chrome/Default/Cache does not exist



guest@porteus:~$ ls /tmp
google-chrome/                qtsingleapp-qlippe-2dfb-3e8-lockfile
qtsingleapp-qlippe-2dfb-3e8=
guest@porteus:~$ ls /tmp/google*
Cache/
guest@porteus:~$ 
But more questions.

How does one turn off the set -x command?

Would

Code: Select all

ln -sf /tmp/google-chrome/Cache    /home/guest/.cache/google-chrome/Default/Cache
accomplish the same thing as the mount --bind command?

I need to reboot and retry this without the set -x command.

OK

Code: Select all

guest@porteus:~$ chrome.sh
/mnt/sda5/porteus3.0/Modules/zchrome.xzm

Chrome ready to run. Press Enter when done using it.
Password:Password:
mount: mount point /home/guest/.cache/google-chrome/Default/Cache does not exist


Password:
/mnt/sda5/porteus3.0/Modules/zchrome.xyzm
guest@porteus:~$ google-chrome/                qtsingleapp-qlippe-2dfb-3e8-lockfile
Ed

Bogomips
Full of knowledge
Full of knowledge
Posts: 2564
Joined: 25 Jun 2014, 15:21
Distribution: 3.2.2 Cinnamon & KDE5
Location: London

Re: autoshutdown??

Post#13 by Bogomips » 22 Mar 2016, 12:11

Ed_P wrote: How does one turn off the set -x command?
set +x :)
Ed_P wrote:Would

Code: Select all

ln -sf /tmp/google-chrome/Cache    /home/guest/.cache/google-chrome/Default/Cache
accomplish the same thing as the mount --bind command?
Which is better I was wondering. Sometimes I've found symlink not to work, so prefer to do mount. AFAIK magic folders also use the mount.

btw suggest enhancing by creating the cache directory:

Code: Select all

if [ ! -d /tmp/google-chrome/Cache ]; then
   mkdir  -p  /tmp/google-chrome/Cache;
  c=/home/guest/.cache/google-chrome/Default/Cache
  [[ ! -d $c ]] && mkdir -p $c
   sudo mount --bind /tmp/google-chrome/Cache  $c
fi 
Linux porteus 4.4.0-porteus #3 SMP PREEMPT Sat Jan 23 07:01:55 UTC 2016 i686 AMD Sempron(tm) 140 Processor AuthenticAMD GNU/Linux
NVIDIA Corporation C61 [GeForce 6150SE nForce 430] (rev a2) MemTotal: 901760 kB MemFree: 66752 kB

User avatar
Ed_P
Contributor
Contributor
Posts: 8360
Joined: 06 Feb 2013, 22:12
Distribution: Cinnamon 5.01 ISO
Location: Western NY, USA

Re: autoshutdown??

Post#14 by Ed_P » 22 Mar 2016, 15:21

Bogomips wrote:Which is better I was wondering. Sometimes I've found symlink not to work, so prefer to do mount. AFAIK magic folders also use the mount.
The symlink I don't think would care if the .cache folder exists when executed. Not sure it also may not require sudo.
btw suggest enhancing by creating the cache directory:

Code: Select all

if [ ! -d /tmp/google-chrome/Cache ]; then
   mkdir  -p  /tmp/google-chrome/Cache;
  c=/home/guest/.cache/google-chrome/Default/Cache
  [[ ! -d $c ]] && mkdir -p $c
   sudo mount --bind /tmp/google-chrome/Cache  $c
fi 
:D Yes, a variable or two would help. And the && is an interesting approach also.

I've really enjoyed this thread Bogomips. It's like the old days for me, asking questions and learning new things. Thank you. :friends:

Newest problem, running chrome I don't see anything in either cache location. :%) :D
Ed

Bogomips
Full of knowledge
Full of knowledge
Posts: 2564
Joined: 25 Jun 2014, 15:21
Distribution: 3.2.2 Cinnamon & KDE5
Location: London

Re: autoshutdown??

Post#15 by Bogomips » 22 Mar 2016, 17:57

Watch movie in browser and use:

Code: Select all

find . -xdev -size +70M
which is what I used in order to find the PaleMoon cache. :D
Ed_P wrote:I've really enjoyed this thread Bogomips. It's like the old days for me, asking questions and learning new things. Thank you. :friends:
I'm all for sharing knowledge and learning new things, myself included. :Search:
Linux porteus 4.4.0-porteus #3 SMP PREEMPT Sat Jan 23 07:01:55 UTC 2016 i686 AMD Sempron(tm) 140 Processor AuthenticAMD GNU/Linux
NVIDIA Corporation C61 [GeForce 6150SE nForce 430] (rev a2) MemTotal: 901760 kB MemFree: 66752 kB

Post Reply