title: How to execute openssl command at shutdown and reboot?
body: <p>I want to encrypt a file and log the time at shutdown or reboot.<br>
  Here is what i do.<br>
  1.edit a bash script file to execute at shutdown or reboot.</p>
  
  <pre><code>vim log.sh
  key="123456"
  openssl enc -des3 -a -salt -in $HOME/test -k ${key} -out $HOME/test.asc
  date &gt;&gt;  /home/log.info
  </code></pre>
  
  <p>2.edit a log.service    </p>
  
  <pre><code>sudo vim /etc/systemd/system/log.service
  [Unit]
  Description=Run command at shutdown
  Before=shutdown.target reboot.target
  
  [Service]
  Type=oneshot
  RemainAfterExit=true
  ExecStop=/bin/bash /home/log.sh
  
  
  [Install]
  WantedBy=multi-user.target
  </code></pre>
  
  <p>3.systemctl enable  log.service<br>
  4.reboot    </p>
  
  <p>After reboot i found that there is a date info in /home/log.info ,it means <code>date &gt;&gt;  /home/log.info</code> executed,no <code>$HOME/test.asc</code> there,it means <code>openssl enc -des3 -a -salt -in $HOME/test -k ${key} -out $HOME/test.asc</code> not executed.<br>
  The commands can run successfully in terminal .   </p>
  
  <pre><code>key="123456"
  openssl enc -des3 -a -salt -in $HOME/test -k ${key} -out $HOME/test.asc
  </code></pre>
  
  <p>How to fix my log.service file <code>/etc/systemd/system/log.service</code> to make openssl command  executed at shutdown and reboot? </p>