I wrote one python script which reads a file offset and file name from a list and divide a one large file into multiple files. For splitting i am using shell script which takes these names and offset as input and create multiple output files using head command. I am using python to send the input to the shell script. This is working fine in my Windows 7, and other Linux systems. But when i am trying to use the same on ESX 6.5 hypervisor, i realize i cannot use the same shell script in ESX 6.5 as head command is not working as it is working in other OS.
list = ['IdleChk_1_E1.txt', '749', 'IdleChk_2_E1.txt', '749', 'reg_fifo_E1.txt', '5922', 'igu_fifo_E1.txt', '161', 'protection_override_E1.txt', '1904', 'fw_asserts_E1.txt', '708', 'McpTrace.txt', '15578', 'phy_dump.txt', '129', 'GrcDumpE1.bin', '3629656']
Even number elements are file name and odd number elements are size.
Here is the command i am using to send input to the shell script:
Process_three=subprocess.Popen("./read.sh %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s" \
%(''.join(map(str, list_info[1:2])), ''.join(map(str, list_info[0:1])),\
''.join(map(str, list_info[3:4])), ''.join(map(str, list_info[2:3])),\
''.join(map(str, list_info[5:6])), ''.join(map(str, list_info[4:5])),\
''.join(map(str, list_info[7:8])), ''.join(map(str, list_info[6:7])),\
''.join(map(str, list_info[9:10])), ''.join(map(str, list_info[8:9])),\
''.join(map(str, list_info[11:12])), ''.join(map(str, list_info[10:11])),\
''.join(map(str, list_info[13:14])), ''.join(map(str, list_info[12:13])),\
''.join(map(str, list_info[15:16])), ''.join(map(str, list_info[14:15])),\
''.join(map(str, list_info[17:18])), ''.join(map(str, list_info[16:17])),\
file_name), stdout=subprocess.PIPE, shell=True)
(temp, error) = Process_three.communicate()
Here is my shell script.
if [ "$#" -eq 19 ];
then
{
head -c $1 > $2
head -c $3 > $4
head -c $5 > $6
head -c $7 > $8
head -c $9 > ${10}
head -c ${11} > ${12}
head -c ${13} > ${14}
head -c ${15} > ${16}
head -c ${17} > ${18}
} < ${19}
fi
In ESX only first head command output is working.
Is there another way to split the file. I know there is split command but this command split the file into two equal halves. I need dynamic size file. I was hoping if i can do the splitting from python itself. By the way I am new to Python.
list_info? Without that it is hard to imagine what you want. This is certainly something that can be done in Python without usingheadandsh! But you have definitely come up with an inventive solution.