Display spinning cursor while waiting


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Display spinning cursor while waiting
# 1  
Old 08-15-2008
Question Display spinning cursor while waiting

Hi All,

I have a script, very basic, that checks the the intergrity of tar files. Of course, with a huge amount of files, this might take a while. So I'd like to have the script display the spinning cursor while this happens. I'm just not sure how to go about scripting this under ksh. Can someone help me out with it?
# 2  
Old 08-15-2008
here is a script to show a spinning cursor. You could probabally put this in a loop waiting for another script to complete.

Code:
#!/bin/bash

# paste following in your script
declare -a Spinner

Spinner=(/ - \\ \| / - \\ \| ) 
Spinnerpos=0

update_spinner()
{
    printf "\b"${Spinner[$Spinnerpos]} 
    (( Spinnerpos=(Spinnerpos +1)%8 ))
}

# testing : 

printf "Spinner :  "

update_spinner
sleep 1
update_spinner
sleep 1
update_spinner
sleep 1
update_spinner
sleep 1
update_spinner
sleep 1
update_spinner
sleep 1
update_spinner
sleep 1
update_spinner
sleep 1
update_spinner
sleep 1
update_spinner
sleep 1
update_spinner
sleep 1
update_spinner

# 3  
Old 08-15-2008
I appears to not work in ksh... Im checking.
# 4  
Old 08-15-2008
this works in ksh on my HP-UX

Code:
# paste following in your script
#declare -a Spinner


#Spinner=(/ - \\ \| / - \\ \| )
set -A Spinner / - \\ \| / - \\ \|
Spinnerpos=0

update_spinner()
{
    printf "\b"${Spinner[$Spinnerpos]}
    (( Spinnerpos=(Spinnerpos +1)%8 ))
}

# testing :

printf "Spinner :  "

update_spinner
sleep 1
update_spinner
sleep 1
update_spinner
sleep 1
update_spinner
sleep 1
update_spinner
sleep 1
update_spinner
sleep 1
update_spinner
sleep 1
update_spinner
sleep 1
update_spinner
sleep 1
update_spinner
sleep 1
update_spinner
sleep 1
update_spinner

# 5  
Old 08-15-2008
I knew how to spin the cursor, but getting the signals to work took a minute...
Code:
#!/bin/ksh

cursor[0]='\|'
cursor[1]='/'
cursor[2]='-'
cursor[3]='\\'
cursor[4]='\|'
cursor[5]='/'
cursor[6]='-'

pos=0
let breakout=1
update_cursor()
{
    printf "\b"${cursor[pos]} 
    pos=$(( ( pos + 1 )  % 7 ))
}

trap "let breakout=0" USR1

#background process sleeps 10 seconds, raise USR1 signal
export this_pid=$$

# tar check goes here where sleep is
sleep 4 && kill -USR1 $this_pid &

echo "spinning cursor sort of.... \c"

while [[ $breakout -eq 1 ]]
do 
  update_cursor
  sleep 1
done

# 6  
Old 08-15-2008
oops - ikon beat me to it...
# 7  
Old 08-15-2008
Thanks all! I appreciate the help. I'm playing with the script now to see how it works for me. Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

IBM P730 running AIX 7.1 (8231-E2B) - Fans spinning loud/max rpm?

We have a IBM P730 machine running AIX 7.1 in a properly air cooled server room. Just recently the fans on the unit kicked into overdrive, they are very loud and spinning at max. Typically this happens when the server first boots then they normalize. However for some odd reason, they sound... (2 Replies)
Discussion started by: c3rb3rus
2 Replies

2. UNIX and Linux Applications

Passing the value of a cursor to another cursor

i have 2 cursors. i want to assign the value of first cursor(employee_id) to the where condition of cursor c2(please refer the bold statement). how do i do if i want to assign the value of c1 to where condition of cursor c2? declare cursor c1 IS select employee_id from employee cursor c2... (1 Reply)
Discussion started by: vkca
1 Replies

3. Shell Programming and Scripting

Getting the cursor position

I need to get the cursor position, and put it inside a variable. Problem is, i don't have the tput command, or ncurses. Apparently I was supposed to try the following: echo -e '\E But I don't get a value or anything. Please help. (3 Replies)
Discussion started by: tinman47
3 Replies

4. Shell Programming and Scripting

Using Cursor in Unix - How to do it (Need Help)

Hi, I have a table in which i have the following data JOB_NO FILE_ID FILE_NAME 1546148 1378788 PDF Sample -1.pdf 1546148 1378789 PDF Sample -2.pdf 1546149 1378790 PDF Sample -3.pdf Now I would like use a cursor like thing in unix to download the files using the file ids and send... (1 Reply)
Discussion started by: uuuunnnn
1 Replies

5. Shell Programming and Scripting

Spinning bar status while doing something.

After some googling, I came across this script to create a spinning cursor: #!/bin/bash # paste following in your script declare -a Spinner Spinner=(/ - \\ \| / - \\ \| ) Spinnerpos=0 update_spinner() { printf "\b"${Spinner} (( Spinnerpos=(Spinnerpos +1)%8 )) } # testing... (2 Replies)
Discussion started by: mrwatkin
2 Replies

6. UNIX for Dummies Questions & Answers

Cursor position

Is there a way of finding the current cursor position (line & column) within AIX (4 Replies)
Discussion started by: gefa
4 Replies

7. Solaris

Custom Spinning Your own Open solaris

I was wondering, If it is at all possible to spin my own custom opensolrais boot disc? The reason i ask is becausrwe i am running Open Solaris on a AMD 64 bit based system and neet flash and MPeg support right out of the box. A prompt answer Is much appreciated. (1 Reply)
Discussion started by: FloridaBSD
1 Replies

8. Shell Programming and Scripting

scrolling cursor

Hi, I'm writing scripts in perl and shell and want to add the oprion of scrolling cursor on the screen when there is no output to the screen for long time. I saw it in some script but I don't have the source code. Are anyone know how can I perform this ? Thanks (1 Reply)
Discussion started by: Alalush
1 Replies

9. UNIX for Dummies Questions & Answers

Blinking cursor

Cursor is blinking (slightly) while loading page in Firefox, or during scrolling a window. I tried some variants of linux (gnome permanently) and of course my solaris. May be an artifact of X-window? Cause in windows cursor is stable (i'm feeling more confident). PS: It makes me nervous. (0 Replies)
Discussion started by: Xcislav
0 Replies

10. UNIX for Dummies Questions & Answers

Cursor Positioning

Can anyone tell me how to ouput the current cursor coordinate? I have tried using tput sc and tput rc. However I want to know what the coordinate is. Thanks. (1 Reply)
Discussion started by: bestbuyernc
1 Replies
Login or Register to Ask a Question