0

I'm trying to clear facebook cache on my server every 2 seconds so i logged in the SSH and i run this command

while true; do sleep 2; curl -F id="http://twd.ma" -F scrape=true -F access_token='token' -F appID=appID https://graph.facebook.com; done &

And every thing worked fine and the cache started to be cleaned every 2 seconds. However, when i close the Terminal SSH the cache stop being cleaned and i think the process is killed, what should i do please?

  • 4
    Stack Overflow is a site for programming and development questions. This question appears to be off-topic because it is not about programming or development. See [What topics can I ask about here](http://stackoverflow.com/help/on-topic) in the Help Center. Perhaps [Super User](http://superuser.com/) or [Unix & Linux Stack Exchange](http://unix.stackexchange.com/) would be a better place to ask. – jww Jan 15 '18 at 23:09

2 Answers2

0

Your command will stop executing because when you log out, the shell is lost. The '&' means that the script runs in background "as long as the shell is active"

You can do the following: Write your script into a file, i.e. clearcache.sh and omit the '&'

#!/bin/bash
while true; do
sleep 2
curl -F id="http://twd.ma" -F scrape=true -F access_token='token' -F appID=appID https://graph.facebook.com
done

Write the path to your script into /etc/rc.local

/path/to/clearcache.sh > /dev/null 2&>1 &

The ' >/dev/null 2&>1 means that all output that your script produces will be deleted.

0

If screen is available to you then you can start a screen session by running screen, run your commands, then press ctrl-a ctrl-d to detach the session.

When you log in later you can issue screen -r to reconnect to the detached session.

shay
  • 755
  • 10
  • 22