Sponsored Content
Top Forums Shell Programming and Scripting Looking for help with a script to automate VLC Post 302321119 by uncertain on Saturday 30th of May 2009 08:22:35 AM
Old 05-30-2009
Looking for help with a script to automate VLC

Hi,
New member here looking for help. This might not be a post for the 'VERY basics' section, so feel free to move it to somewhere more appropriate.

I've created a script that searches my computer for video files, creates a list of these files, and selects a number of random entries to play in VLC. After a recent catastrophic external HDD failure, everything I could recover has been moved to two computers on a LAN. Now, instead of just searching my ~/Videos folder for the files to index and play, I have to search the ~/Videos folder of a second computer as well, index those (appended to the same list, preferably), and include them in the random shuffle I've created.

I have SSH & SCP access on both machines (I recently learned how to implement passwordless-ssh using rsa & dsa keyfiles, specifically so these processes could be automated). I don't have Samba or NFS installed or working on either computer, but I'll install and configure them if need be. (Though I'd rather not install, configure, and enable NFS or Samba, edit fstab, and then auto-mount a remote folder at boot just to do this.) Just today, I've learned how to start VLC on the remote computer in network-streaming mode, and then start VLC on the local host in network-capture mode. All I'm having a hard time conceptualizing is how to implement the indexing process from a script on the local machine to list files on a remote machine.

Here's a copy of my script in its' current state. It's the first BASH scripting project I ever tackled, and 'borrowed' bits & pieces of it from various things I found via Google. I'm sure there's a better/smoother/cleaner way to do some of the things I did, but it works, and I'm happy with it. Right now, it's set to index all the episodes of The Simpsons that are in my hard drive, and then play several random episodes.

If anyone could point me in a direction or give me some pointers, I'd greatly appreciate it.
Code:
#!/bin/bash
#
# Creates a list of all files in all Simpsons folders and then
# plays so many random episodes with VLC Media Player.
# Created by Uncertain

# Filenames and paths.
path1=/home/zero/Videos/
path2=/home/zero/Videos/Simpsons
list=/home/zero/Videos/Simpsons/episodes.txt
# Check for the list. If it's in ~/Videos, fine.
# If it doesn't exist, create it in ~/Videos.
if [ -f $list ]
 then
  echo "List found at $list"
   else
    echo "Episodes list not found. Creating list arranged by season & episode..." && cd $path1 && find ~/Videos/Simpsons -name '*.avi' -o -name '*.mpg' -o -name '*.mp4' -o -type f -size +20M | sort > $list && echo "Done. List created at: $list" 
fi
# Set the number of episodes to play. Episodes are 
# roughly 20 mins, so three episodes to every hour.
repeat=3
cycles=0
while  [ $cycles -ne $repeat ]
 do
  echo $cycles
  cycles=$(( $cycles + 1 ))
# Read the list, select one random line.
LowerBound=1
RandomMax=32767
UpperBound=$(cat $list | wc -l)
RandomLine=$(( $LowerBound + ($UpperBound * $RANDOM) / ($RandomMax + 1) ))
# Use sed to grab the random line.
episode=$(sed -n "$RandomLine{p;q;}" "$list")
# open the random line in VLC
vlc -vvv --fullscreen "$episode" vlc:quit
# Close the episode count loop...
  done
# ...and then...
exit


Last edited by uncertain; 05-30-2009 at 10:43 AM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

automate the input in a script

I have a program that i have to run by cron. The program needs user input. So i have to automate that in a littke script. start of script program.sh: result=program.log; export result echo Program starting : `date` >> $result /usr/local/program >> $result echo Program running : `date` >>... (11 Replies)
Discussion started by: erwinspeybroeck
11 Replies

2. Shell Programming and Scripting

here document to automate perl script that call script

I am trying to use a here document to automate testing a perl script however when the perl script hits a system(perl subscript.pl) call, input is no longer entered into this subscript. here is my script $ cat test.sh #ksh for testcase do program <<-EOF | tee -a funcscnlog.log y... (3 Replies)
Discussion started by: hogger84
3 Replies

3. Shell Programming and Scripting

Script(s) to Automate Tasks

I know that this has a bad title, but I'm not sure how to sum it up well. (And I'm new to Linux in general, so please excuse any incorrect terminology :o) Anyway, I'm trying to create a script that gets whatever folder you're in, and then does a command with that directory as an argument. I... (2 Replies)
Discussion started by: droppedonjapan
2 Replies

4. UNIX for Advanced & Expert Users

Shell Script to Automate

I would like to automate script where i do not have to manually insert the username and password I wrote two different scripts but not able to achieve the results: here's to scripts i wrote #!/bin/bash cd /var/tmp /home/server/steve/pca --askauth -idx /opt/app/bin/expect <<EOF expect... (1 Reply)
Discussion started by: sam786
1 Replies

5. Shell Programming and Scripting

Automate shell script

I would like to automate script where i do not have to manually insert the username and password I wrote two different scripts but not able to achieve the results: here's to scripts i wrote #!/bin/bash cd /var/tmp /home/server/steve/pca --askauth -idx /opt/app/bin/expect <<EOF expect... (3 Replies)
Discussion started by: sam786
3 Replies

6. Shell Programming and Scripting

Automate Script ***V. Urgent

Hi All, ./procdure.ksh which opens the below the menu, I want to build a script which will press 4 and run the Sector Data Automatically (instead of pressing option 4 manually) Is there any way for this, please let me know... 1) FX Rates MDU 9) Fidessa Cash... (7 Replies)
Discussion started by: niceboykunal123
7 Replies

7. Shell Programming and Scripting

How can I automate a script?

Hi All, Can I automate a script when some one trying to 'vi' (open) a file. For Example, I am having a file named 'SecuredShell.sh'. when a user types " vi SecuredShell.sh " in unix command prompt a script named secure.sh needs to be automated. Can this be possible. if Yes please guide... (2 Replies)
Discussion started by: little_wonder
2 Replies

8. Shell Programming and Scripting

mail script to automate

Hi, Here below the logs from the mail server: less /var/log/messages: Sep 6 04:03:31 server-59 out: 1252227811|webmaster@zilia.com|antonino.granata@gmail.com|2175|success|1 Sep 6 04:03:33 server-59 in: 1252227813|news@tarot.com|junk@thess.com|30376|success|1 Sep 6 04:03:35 server-59... (8 Replies)
Discussion started by: gsiva
8 Replies

9. Shell Programming and Scripting

Automate remote script

Hi all, I need to execute a script on a remote machine that are connected to the network.The basic requirement is to write a script which will login in remote machine and then execute the other script automatically placed in remote machine.So that I need to execute the remote machine script... (3 Replies)
Discussion started by: smartgupta
3 Replies

10. Windows & DOS: Issues & Discussions

automate the script

Dear all, I I want to login to my Linux machine using putty and then run some script from Windows machine.we can do it after loging it and then execute the script by typing it in putty command line screen. but I want to automate it.So whenever I will fire this script,it will do the following... (4 Replies)
Discussion started by: smartgupta
4 Replies
RANDOM(4)						     Linux Programmer's Manual							 RANDOM(4)

NAME
random, urandom - kernel random number source devices DESCRIPTION
The character special files /dev/random and /dev/urandom (present since Linux 1.3.30) provide an interface to the kernel's random number generator. File /dev/random has major device number 1 and minor device number 8. File /dev/urandom has major device number 1 and minor device number 9. The random number generator gathers environmental noise from device drivers and other sources into an entropy pool. The generator also keeps an estimate of the number of bit of the noise in the entropy pool. From this entropy pool random numbers are created. When read, the /dev/random device will only return random bytes within the estimated number of bits of noise in the entropy pool. /dev/random should be suitable for uses that need very high quality randomness such as one-time pad or key generation. When the entropy pool is empty, reads to /dev/random will block until additional environmental noise is gathered. When read, /dev/urandom device will return as many bytes as are requested. As a result, if there is not sufficient entropy in the entropy pool, the returned values are theoretically vulnerable to a cryptographic attack on the algorithms used by the driver. Knowledge of how to do this is not available in the current non-classified literature, but it is theoretically possible that such an attack may exist. If this is a concern in your application, use /dev/random instead. CONFIGURING
If your system does not have /dev/random and /dev/urandom created already, they can be created with the following commands: mknod -m 644 /dev/random c 1 8 mknod -m 644 /dev/urandom c 1 9 chown root:root /dev/random /dev/urandom When a Linux system starts up without much operator interaction, the entropy pool may be in a fairly predictable state. This reduces the actual amount of noise in the entropy pool below the estimate. In order to counteract this effect, it helps to carry entropy pool informa- tion across shut-downs and start-ups. To do this, add the following lines to an appropriate script which is run during the Linux system start-up sequence: echo "Initializing kernel random number generator..." # Initialize kernel random number generator with random seed # from last shut-down (or start-up) to this start-up. Load and # then save 512 bytes, which is the size of the entropy pool. if [ -f /var/random-seed ]; then cat /var/random-seed >/dev/urandom fi dd if=/dev/urandom of=/var/random-seed count=1 Also, add the following lines in an appropriate script which is run during the Linux system shutdown: # Carry a random seed from shut-down to start-up for the random # number generator. Save 512 bytes, which is the size of the # random number generator's entropy pool. echo "Saving random seed..." dd if=/dev/urandom of=/var/random-seed count=1 FILES
/dev/random /dev/urandom AUTHOR
The kernel's random number generator was written by Theodore Ts'o (tytso@athena.mit.edu). SEE ALSO
mknod (1) RFC 1750, "Randomness Recommendations for Security" Linux 1997-08-01 RANDOM(4)
All times are GMT -4. The time now is 05:37 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy