Bash Script - File Size


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Bash Script - File Size
# 1  
Old 05-11-2014
Bash Script - File Size

I have a bash script. I need a modification for safety.

my original bash script:

Code:
mv /home/script/backup /home/script/backup2
mysql -u user -ppassword -Ddatabase --batch --skip-column-names -e 'select id, url from videos where url like "%http%" limit 1' | 
while read id url

do youtube-dl -o "/home/script/uploads/$id.mp4" -f 18/17/22/mp4 "$url"
done

mysql -u user -ppassword -Ddatabase -e "UPDATE videos SET url=CONCAT(id,'.mp4') WHERE url LIKE '%http%' limit 1" ;
mysql -u user -ppassword -Ddatabase -e "UPDATE videos SET source_id='1' WHERE source_id in (3) limit 1";
mv /home/script/backup2 /home/script/backup
exit

I need this bash script:

Code:
mv /home/script/backup /home/script/backup2
mysql -u user -ppassword -Ddatabase --batch --skip-column-names -e 'select id, url from videos where url like "%http%" limit 1' | 
while read id url

do youtube-dl -o "/home/script/uploads/$id.mp4" -f 18/17/22/mp4 "$url"
done

here: I want to check the file size. if it is greater than 10 KB I want to run the following all commands.

Code:
mysql -u user -ppassword -Ddatabase -e "UPDATE videos SET url=CONCAT(id,'.mp4') WHERE url LIKE '%http%' limit 1" ;
mysql -u user -ppassword -Ddatabase -e "UPDATE videos SET source_id='1' WHERE source_id in (3) limit 1";
mv /home/script/backup2 /home/script/backup
exit

If less than 10 KB or not found a file, I want to run only this command.

Code:
mv /home/script/backup2 /home/script/backup
exit

# 2  
Old 05-11-2014
Not sure I understand what you need. Try (if available on your system)
Code:
[ $(stat -c "%s" file) -ge 10240 ] && {
mysql -u user -ppassword -Ddatabase -e "UPDATE videos SET url=CONCAT(id,'.mp4') WHERE url LIKE '%http%' limit 1"
mysql -u user -ppassword -Ddatabase -e "UPDATE videos SET source_id='1' WHERE source_id in (3) limit 1"
}

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Bash script to get total size off of remainder calculated

I am working on a script to get the final total size and so far have the following and wondering if this can be improved. # Compare the desired size of each lvm to the standard size. If it is desired is larger than calculate the difference and keep that value as the amount to add to that LVM. ... (5 Replies)
Discussion started by: user3528
5 Replies

2. Shell Programming and Scripting

Need help in finishing a bash script for listing subfolder by size in a large folder

Greetings everyone. I have seen that you do wonders here. I have a large folder on a Ubuntu linux. Organization main folder, inside 20 000 subfolders, and inside those subolders many other like 5-6 folders and files. I am interested to create an output to a txt file under the bash... (2 Replies)
Discussion started by: ultimo
2 Replies

3. Shell Programming and Scripting

Split file based on file size in Korn script

I need to split a file if it is over 2GB in size (or any size), preferably split on the lines. I have figured out how to get the file size using awk, and I can split the file based on the number of lines (which I got with wc -l) but I can't figure out how to connect them together in the script. ... (6 Replies)
Discussion started by: ssemple2000
6 Replies

4. Shell Programming and Scripting

Script to read file size and send email only if size > 0.

Hi Experts, I have a script like $ORACLE_HOME/bin/sqlplus username/password # << ENDSQL set pagesize 0 trim on feedback off verify off echo off newp none timing off set serveroutput on set heading off spool Schemaerrtmp.txt select ' TIMESTAMP COMPUTER NAME ... (5 Replies)
Discussion started by: welldone
5 Replies

5. Shell Programming and Scripting

bash script directory size

hello! i need to make a script that get a folder name in parameter and i get back the size of the folder include the subfolders! but i dont know how i need to start :S Example: a folder contain the followings a: drwxr-xr-x 2 user user 4096 febr 25 08.27 b -rw-r--r-- 1 user user 2 febr... (3 Replies)
Discussion started by: impish
3 Replies

6. Shell Programming and Scripting

bash: checking file size -solved

Hello I have srv RHEL5, file system UTDM (EMC DiskXtender Unix/Linux File System Manager 3.5 & EMC Centera). it all works under the scheme: have disk is formatted with a file system UTDM, drive open network - NFS, it write data, then migrate the data in the repository - EMC Centera. There are... (0 Replies)
Discussion started by: moskovets
0 Replies

7. Shell Programming and Scripting

script to get file size

Hi All, I have some requirement. i dont know if we can write some shell script to fulfill the requirement. Here is my requirement... I have some files under /var/opt/abc/xyz like below. -rw-r--r-- 1 root root 789222 Aug 14 11:03 big.sh -rw-r--r-- 1 root root 789222 Aug 14 11:03 big.txt... (25 Replies)
Discussion started by: s_linux
25 Replies

8. Shell Programming and Scripting

compare file size from a output file from a script

Hi guys, firstly I'm working on SunOS 5.10 Generic_125100-10 sun4u sparc SUNW,Sun-Fire-V240 I've made a script to compress two directory and then send them to an other server via ftp. This is working very well. Inside theis script I decide to log usefull data for troubleshooting in case of... (7 Replies)
Discussion started by: moustik
7 Replies

9. Shell Programming and Scripting

bash script working for small size files but not for big size files.

Hi, I have one file stat. Stat file contents are as follows: for example. H50768020040913,00260100,507680,13,0000000643,0000000643,00000,0000 H50769520040808,00260100,507695,13,0000000000,0000000000,00000,0000 H50770620040611,00260100,507706,13,0000000000,0000000000,00000,0000 Now i... (1 Reply)
Discussion started by: davidpreml
1 Replies

10. UNIX for Dummies Questions & Answers

file size script

Hi, I am trying to write a script that will send an email to me if the size of a folder is below a certain amount. Does anyone know how to write the if (size < 1000) statement. I know how to send the email? I just need the code for determing a folder size. Thanks, Eric (5 Replies)
Discussion started by: ejbrever
5 Replies
Login or Register to Ask a Question