You are not logged in.

#1 2010-12-18 19:05:34

STANKAR
Member
From: Czech Republic
Registered: 2010-11-16
Posts: 47

[SOLVED] Help with shell script

Hi, now I need a script that will print a dots until it is copied and count will be max 5, where there will be more, so the dots will be deleted and re-print, like loading

I have only this, but it's not good:

#/bin/bash

count = 0

while [ cp -r /root /media/backup/ARCH ]       # this is for orientation, wrong
    do printf "."
    (( $count++ ))
    sleep 1s
    if [ $count == 5 ]
        then clear            # this could clear 4 dots, wrong again
        count = 0
    fi
done

     

Thanks for help

Last edited by STANKAR (2010-12-28 15:32:53)

Offline

#2 2010-12-18 19:08:55

STANKAR
Member
From: Czech Republic
Registered: 2010-11-16
Posts: 47

Re: [SOLVED] Help with shell script

and i forgot, integer count should be in while condition with copy, but i cannot make the condition

Offline

#3 2010-12-18 19:39:56

falconindy
Developer
From: New York, USA
Registered: 2009-10-22
Posts: 4,111
Website

Re: [SOLVED] Help with shell script

quick n dirty... replace 'sleep 10' with whatever your long running task is.

#!/bin/bash

sleep 10 &
pid=$!
while [[ -d /proc/$pid ]]; do
  (( ++dots ))
  printf "\r% *s" $(( dots % 5 )) "" | tr ' ' '.'
  printf "% *s" $(( 5 - dots % 5 )) ""
  sleep .5s
done
echo

Last edited by falconindy (2010-12-18 19:42:20)

Offline

#4 2010-12-18 19:45:09

falconindy
Developer
From: New York, USA
Registered: 2009-10-22
Posts: 4,111
Website

Re: [SOLVED] Help with shell script

Personally, i prefer the spinner:

#!/bin/bash

spinner='|/-\'
sleep 10 &
pid=$!
while [[ -d /proc/$pid ]]; do
  printf '\r%c' ${spinner:count:1}
  count=$(( ++count % ${#spinner} ))
  sleep .5
done
echo

Offline

#5 2010-12-18 19:45:09

STANKAR
Member
From: Czech Republic
Registered: 2010-11-16
Posts: 47

Re: [SOLVED] Help with shell script

Wow, i think, that will be shorter code big_smile But nice job. Last thing what i need is construct while condition ...

Offline

#6 2010-12-18 21:36:22

STANKAR
Member
From: Czech Republic
Registered: 2010-11-16
Posts: 47

Re: [SOLVED] Help with shell script

STANKAR wrote:

Wow, i think, that will be shorter code big_smile But nice job. Last thing what i need is construct while condition ...

Oh god, i'm idiot, previous code is complete, no while is need. THX again falconindy

Offline

Board footer

Powered by FluxBB