Check for download before running command


 
Thread Tools Search this Thread
Operating Systems Linux Ubuntu Check for download before running command
# 8  
Old 03-24-2019
I think I am hopeless with the if, then while, etc.

I had it working until I added code to check for downloads.

I can definitely live without it.

This script will suspend computer in 10 minutes if there is no mouse or keyboard activity.
/home/andy/bin/test_dl.sh: line 26: syntax error near unexpected token `fi'
/home/andy/bin/test_dl.sh: line 26: `fi'
Code:
for file in /home/andy/Downloads/*.part ; do
    if [[ -f $file ]]; then
        echo "File download in progress."
        echo "Computer can not suspend until download is complete."
        echo "Now exiting."
        exit
    fi
done

echo "This script will suspend computer in 10 minutes if there is no mouse or keyboard activity."
sleep 1
  if (( $(xprintidle) >= 600000 )); 
    systemctl suspend
then

fi

# 9  
Old 03-24-2019
Please note that I have never seen any shell complain about a problem on line 26 in a shell script that only contains 16 lines???

The syntax for an if command is:
Code:
if condition
then	command...
fi

not:
Code:
if condition
	command...
then
fi

This User Gave Thanks to Don Cragun For This Post:
# 10  
Old 03-25-2019
Help me out - threads over threads you are trying to mimic a function / behaviour that "professional" packages like screen savers offer at no cost. Why?
This User Gave Thanks to RudiC For This Post:
# 11  
Old 03-25-2019
Hi drew...

Tell us what your project is or what you are trying to achieve then perhaps we can help you with it as a complete proper entity.

Some of the snippet code threads you have started are not portable at all, 'xinput' for example will not work on at least APPLE gear and CygWin for Windows as they don't have it.
'systemctl' will not work on many *NIX like flavours as they don't have it either. I can't test any of your code on this MacBook Pro without rebooting into Linux Mint 19.
This can become tedious...

EDIT:
Just checked and Linux Mint 19 does NOT have 'xprintidle' either on a default install.

Last edited by wisecracker; 03-25-2019 at 06:58 AM.. Reason: See EDIT:
# 12  
Old 03-25-2019
Quote:
Originally Posted by wisecracker
Hi drew...

Tell us what your project is or what you are trying to achieve then perhaps we can help you with it as a complete proper entity.

Some of the snippet code threads you have started are not portable at all, 'xinput' for example will not work on at least APPLE gear and CygWin for Windows as they don't have it.
'systemctl' will not work on many *NIX like flavours as they don't have it either. I can't test any of your code on this MacBook Pro without rebooting into Linux Mint 19.
This can become tedious...

EDIT:
Just checked and Linux Mint 19 does NOT have 'xprintidle' either on a default install.
Thanks for everyone's help.

I am happy with this. Checking for a download is not critical.

Code:
#!/bin/bash
#----------------------------------------------------------------------------
# SUSPEND COMPUTER IF NO MOUSE/KEYBOARD ACTIVITY FOR 10 MINUTES
#
# The time is in milliseconds !! 300000 = 5 minutes
#
# This is good to put in startup programs
#
# Much help from The UNIX and Linux Forums  - Free Tech Support
#----------------------------------------------------------------------------
echo "This script will suspend computer in 10 minutes if there is no mouse or keyboard activity."
while :; do
  if (( $(xprintidle) >= 600000 )); then
    systemctl suspend
fi
  sleep 0.5
done

# 13  
Old 03-25-2019
Quote:
Originally Posted by RudiC
Help me out - threads over threads you are trying to mimic a function / behaviour that "professional" packages like screen savers offer at no cost. Why?
Screen savers do not save as much energy nor reduce computer wear and tear like suspend does.
# 14  
Old 03-25-2019
I'm afraid you're totally off track here. Screen savers - esp. on Ubuntu 18.10 - cooperate with power management and can be configured to include suspend (or even hibernation, I think).
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Check if process is running if not then use command

Hello, Could someone do the following bash ubuntu script for me? I have 5 screen processes of bot: SCREEN -dmS Xbot_instance_1 php core.php -i 1 SCREEN -dmS Xbot_instance_2 php core.php -i 2 SCREEN -dmS Xbot_instance_3 php core.php -i 3 SCREEN -dmS Xbot_instance_4 php core.php -i 4 ... (2 Replies)
Discussion started by: kotch
2 Replies

2. Shell Programming and Scripting

Check if remote destination is available before running scp command

I have a script on a Linux box which scp the files to windows server without any issues. but there are time frames where the windows server will not be available due to maintenance. hence I need to check if the remote location is available before running the scp command. scp... (3 Replies)
Discussion started by: gpk_newbie
3 Replies

3. Shell Programming and Scripting

Command to check only Autosys running jobs with autorep like command

Hi, Is there any specific command to use to check only say Running jobs via autorep or similar command for Autosys? (0 Replies)
Discussion started by: sidnow
0 Replies

4. Shell Programming and Scripting

Check to see if script is already running

Happy New Year Is there a quick way to check to see if a script is already running. I want to put in a check in the script to exit, if already running. Currerntly i can only think of doing it the following way. # ps -ef | grep -i 3_HOUSEKEEPING_FFTVTL_TO_FFTDSSU_DUPLICATION.ksh |... (5 Replies)
Discussion started by: Junes
5 Replies

5. Shell Programming and Scripting

Check email and download attachment

Hi, I had search the web for a script to download email, but failed to found one. I need a bash or perl script that will check for email originating from an address such as john@rambo.com and download the .zip attachment into a specified folder. Anyone could assist or give me some... (1 Reply)
Discussion started by: mynullvoid
1 Replies

6. Shell Programming and Scripting

Check what cron is running

How to check what cron is scheduled to run? I don't want to modify anything. Thanks (1 Reply)
Discussion started by: stevensw
1 Replies

7. UNIX for Dummies Questions & Answers

Command to check if a particular process is running

Hi What is the best command to check if a particular process is running in a linux server or not To check any java process, I use the below command. ps -ef |grep jvm When I execute the above command, it lists me all the processess . The above command should ideally return only the... (6 Replies)
Discussion started by: vr3w3c9
6 Replies

8. UNIX and Linux Applications

How to check if process is running?

Hi I would like to check if an instance of a script is already running. I've seen many different examples, but I haven't the slightest idea as to how to do this. Can you please help. Thank you. (5 Replies)
Discussion started by: ladyAnne
5 Replies

9. Shell Programming and Scripting

Check if Process is running

Hi , I have a csh code below which check the process if it's running. Can any expert advise me on the following: 1) what does this notationmean ">!" and how is it different from the append ">" notation ? 2) how does "setenv" work in this code ? # Check whether there is a running... (3 Replies)
Discussion started by: Raynon
3 Replies

10. UNIX for Dummies Questions & Answers

Check if deamons are running

Does anyone know if there is a UNIX-tool available that constantly will check if (some specific) deamons are running and will notify (via email) if one has failed/stopped? I searched the web, but so far didn't find anything. (3 Replies)
Discussion started by: W2W
3 Replies
Login or Register to Ask a Question