Something as simple as this is working surely
#!/bin/bash
touch /sdcard/successful.txt
But its not working in my actual bash command
#!/bin/bash
PACKAGE='com.mixplorer'
if [ $(pidof $PACKAGE) ]; then
am force-stop com.mixplorer && am start -n com.mixplorer/.activities.BrowseActivity
fi
if [ ! $(pidof $PACKAGE) ]; then
am start -n com.mixplorer/.activities.BrowseActivity
fi
loopcleaner()
{
rm -rf /sdcard/log.txt
}
while [ $(pidof $PACKAGE) ]
do
loopcleaner
sleep 2
if [ ! $(pidof $PACKAGE) ]; then
touch /sdcard/successful.txt
exit 0;
fi
done
Explanation:
As soon as script is executed , first check if file manager with package name 'com.mixplorer' is active If yes , then force stop it and open it again If no , then just simply open it.
Now that the file manager is already opened , keep deleting a file named 'log.txt' as defined by loopcleaner every 10 seconds in a loop forever as long as file manager process is running.
The above cleaning activity should work only till file manager process is running , Once it stops create a file named successful.txt .Script should end immediately now.
So after i have exited my file manager , the successful.text doesn't gets created in my internal storage for some reason ( which works well if simply touch command is executed )
touch
out of thewhile
loop?touch
after thedone
. You can drop theif
then and avoid the (theoretical) chance that file manager process exits betweenif
check andwhile
check.