System = RHEL 7
Python v = 2.7
Using the code below, I am using file_list and random_choice to randomly select one filename from a given DIR of many files
/MyDir/bin/messages/messagesix.txt
Using XARGS (or some other means) I would like to take that output and construct and execute a simple CP command, which effectively copies the randomly selected file to another directory with filename message.txt, something like the below.
cp strOut /MyDir/bin/message.txt
Normally, I would post my attempted code, but my attempts have been feeble and miserable failures at best.
Any help would be greatly appreciated.
Python v = 2.7
Using the code below, I am using file_list and random_choice to randomly select one filename from a given DIR of many files
#!/usr/bin/env python # -*- coding: utf-8 -*- import random import subprocess file_list = ['/MyDir/bin/messages/messageone.txt', '/MyDir/bin/messages/messagetwo.txt', '/MyDir/bin/messages/messagethree.txt', '/MyDir/bin/messages/messagefour.txt', '/MyDir/bin/messages/messagefive.txt', '/MyDir/bin/messages/messagesix.txt', '/MyDir/bin/messages/messageseven.txt', '/MyDir/bin/messages/messageeight.txt', '/MyDir/bin/messages/messagenine.txt', '/MyDir/bin/messages/messageten.txt' ] strOut = random.choice(file_list) print strOutThe random file selected output currently looks like this:
/MyDir/bin/messages/messagesix.txt
Using XARGS (or some other means) I would like to take that output and construct and execute a simple CP command, which effectively copies the randomly selected file to another directory with filename message.txt, something like the below.
cp strOut /MyDir/bin/message.txt
Normally, I would post my attempted code, but my attempts have been feeble and miserable failures at best.
Any help would be greatly appreciated.