I use php to convert pdf to jpeg but sometimes it’s very slow. So, the solution is to use poppler and use pdftoppm directly to shell.
Category Archives: Hosting
exec and exec_shell in php
If you are using blanks in filenames or any other special character then you need to use escapeshellarg.
https://stackoverflow.com/questions/43513228/php-shell-exec-failed-due-to-some-specific-character
Also, exec and exec_shell are returning status and string of the last command executed (read docs) but it’s somewhat hard to understand when it’s true or false. I didn’t manage to use === operator to check logical expressions returned from the ran command.
https://stackoverflow.com/questions/41212053/php-shell-exec-and-exec-returning-false-when-ran
Also,for pdf merging use:
https://stackoverflow.com/questions/2507766/merge-convert-multiple-pdf-files-into-one-pdf
Rsync exclude include
rsync -av --include '*.md' --include '*/' --exclude '*' --prune-empty-dirs src/ dst/
https://unix.stackexchange.com/questions/741904/rsync-to-exclude-everything-except-specific-files
PDF to JPEG
If you need to convert pdf to jpg I was working with php but it might be slow, obviously. But if you are using linux shell then it’s easier and faster.
72 dpi (web) = 595 X 842 pixels
300 dpi (print) = 2480 X 3508 pixels
600 dpi (print) = 4960 X 7016 pixels
Merge pdf with single command in linux
Poppler has one command to merge all pdfs from folder:
pdfunite *.pdf out.pdf
https://stackoverflow.com/questions/2507766/merge-convert-multiple-pdf-files-into-one-pdf
Change character in filename linux bash
I’m figuring this out for some time. It’s not that I can’t read but most of the time when trying out bash stuff you can make more damage then good to your system so you have to be really really easy.
Now, this one here makes the difference. I had a job to change & in many many many files in different directories and subdirectories and after trying many scripts this one came up working just fine and fast.
find . -type f -exec rename 's/string1/string2/g' {} +
If you want to target specific filename extension then you need to add:
find . -type f -name "*.webp" -exec rename 's/&/-/g' {} +
It was taken from here:
https://unix.stackexchange.com/questions/416018/how-to-replace-a-string-in-all-folder-and-file-names
Bash script for transferring files
url="187.2.2.2"
domain="somedomain.com"
db_user="nikola_db2"
db_database="nikola_db2"
cd /home/nikola/web/$domain/public_html/
rm -rf $db_database*
mysqldump --skip-tz-utc -u$db_user -psomething $db_database > $db_database.sql --net-buffer-length 16777216
ssh -p 4444 nikola@$url 'cd /home/nikola/web/'"$domain"'/public_html/; rm -rf '"$db_database"'*;'
rsync -avz -e "ssh -p 4444" /home/nikola/web/$domain/public_html/$db_database.sql nikola@$url:/home/nikola/web/$domain/public_html/
ssh -p 4444 nikola@$url 'cd /home/nikola/web/'"$domain"'/public_html/; mysql -'"$db_user"' -psomething '"$db_database"' < '"$db_database"'.sql'
rsync -avz -e "ssh -p 4444" /home/nikola/web/$domain/public_html/ nikola@$url:/home/nikola/web/$domain/public_html/
#rsync -avz -e "ssh -p 4444" /home/users/nikola/www/somedomain.com/ nikola@$url:/home/users/nikola/www/somedomain.com/
Mogrify and delete all from current folder and subfolders
Here is some nice code for converting all jpg to webp and also code for deleting all files excluding .webp or any other you want. This is for my personal reference 🙂
nohup find . -type f -regex ".*\.\(jpg\|jpeg\)" -exec mogrify -quality 40 -format webp {} \; -print &
find . -type f ! \( -name "*.webp" \) -exec rm -rf {} \;
Biggest folders in current path
If you need to find what is the biggest folders in current path in linux then this is the command:
du -sh * 2>/dev/null | sort -h
It needs couple of seconds to calculate (if you have slow io vps or hdd) and this is what you get:
root@vps3345:/home/nick/web# du -sh * 2>/dev/null | sort -h
713M alle.ch
1.1G moji.com
1.6G rab.de
1.8G zoek.nl
2.5G al.at
5.4G mojia.si
7.6G a.co.uk
11G sle.cz
13G akceer.com
het
top - 22:09:43 up 1 min, 1 user, load average: 0.11, 0.05, 0.02
Tasks: 169 total, 1 running, 168 sleeping, 0 stopped, 0 zombie
top - 22:09:47 up 1 min, 1 user, load average: 0.11, 0.05, 0.02
Tasks: 169 total, 1 running, 168 sleeping, 0 stopped, 0 zombie
%Cpu(s): 0.0 us, 1.5 sy, 0.0 ni, 98.5 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
MiB Mem : 64096.2 total, 63708.6 free, 250.6 used, 137.0 buff/cache
MiB Swap: 32768.0 total, 32768.0 free, 0.0 used. 63325.1 avail Mem PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 787 root 20 0 10520 3840 3224 R 6.7 0.0 0:00.01 top 1 root 20 0 165876 11176 8128 S 0.0 0.0 0:00.77 systemd 2 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kthreadd 3 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 rcu_gp 4 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 rcu_par_gp 5 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 slub_flushwq 6 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 netns 7 root 20 0 0 0 0 I 0.0 0.0 0:00.00 kworker/0:0-events 8 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 kworker/0:0H-events_highpri 9 root 20 0 0 0 0 I 0.0 0.0 0:00.48 kworker/u16:0-events_unbound 10 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 mm_percpu_wq 11 root 20 0 0 0 0 S 0.0 0.0 0:00.00 rcu_tasks_rude_ 12 root 20 0 0 0 0 S 0.0 0.0 0:00.00 rcu_tasks_trace 13 root 20 0 0 0 0 S 0.0 0.0 0:00.00 ksoftirqd/0 14 root 20 0 0 0 0 I 0.0 0.0 0:00.01 rcu_sched 15 root rt 0 0 0 0 S 0.0 0.0 0:00.00 migration/0 16 root -51 0 0 0 0 S 0.0 0.0 0:00.00 idle_inject/0 17 root 20 0 0 0 0 I 0.0 0.0 0:00.00 kworker/0:1-events 18 root 20 0 0 0 0 S 0.0 0.0 0:00.00 cpuhp/0 19 root 20 0 0 0 0 S 0.0 0.0 0:00.00 cpuhp/1 20 root -51 0 0 0 0 S 0.0 0.0 0:00.00 idle_inject/1 21 root rt 0 0 0 0 S 0.0 0.0 0:00.33 migration/1 22 root 20 0 0 0 0 S 0.0 0.0 0:00.00 ksoftirqd/1 23 root 20 0 0 0 0 I 0.0 0.0 0:00.00 kworker/1:0-mm_percpu_wq 24 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 kworker/1:0H-events_highpri 25 root 20 0 0 0 0 S 0.0 0.0 0:00.00 cpuhp/2 26 root -51 0 0 0 0 S 0.0 0.0 0:00.00 idle_inject/2 27 root rt 0 0 0 0 S 0.0 0.0 0:00.33 migration/2 28 root 20 0 0 0 0 S 0.0 0.0 0:00.00 ksoftirqd/2 29 root 20 0 0 0 0 I 0.0 0.0 0:00.00 kworker/2:0-events 30 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 kworker/2:0H-events_highpri 31 root 20 0 0 0 0 S 0.0 0.0 0:00.00 cpuhp/3 32 root -51 0 0 0 0 S 0.0 0.0 0:00.00 idle_inject/3 33 root rt 0 0 0 0 S 0.0 0.0 0:00.33 migration/3 34 root 20 0 0 0 0 S 0.0 0.0 0:00.00 ksoftirqd/3 35 root 20 0 0 0 0 I 0.0 0.0 0:00.00 kworker/3:0-events 36 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 kworker/3:0H-events_highpri 37 root 20 0 0 0 0 S 0.0 0.0 0:00.00 cpuhp/4 38 root -51 0 0 0 0 S 0.0 0.0 0:00.00 idle_inject/4 39 root rt 0 0 0 0 S 0.0 0.0 0:00.33 migration/4 40 root 20 0 0 0 0 S 0.0 0.0 0:00.00 ksoftirqd/4 41 root 20 0 0 0 0 I 0.0 0.0 0:00.00 kworker/4:0-events 42 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 kworker/4:0H-events_highpri 43 root 20 0 0 0 0 S 0.0 0.0 0:00.00 cpuhp/5 44 root -51 0 0 0 0 S 0.0 0.0 0:00.00 idle_inject/5 45 root rt 0 0 0 0 S 0.0 0.0 0:00.33 migration/5 46 root 20 0 0 0 0 S 0.0 0.0 0:00.00 ksoftirqd/5 47 root 20 0 0 0 0 I 0.0 0.0 0:00.00 kworker/5:0-ipv6_addrconf 48 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 kworker/5:0H-events_highpri 49 root 20 0 0 0 0 S 0.0 0.0 0:00.00 cpuhp/6 50 root -51 0 0 0 0 S 0.0 0.0 0:00.00 idle_inject/6 51 root rt 0 0 0 0 S 0.0 0.0 0:00.33 migration/6 52 root 20 0 0 0 0 S 0.0 0.0 0:00.00 ksoftirqd/6 53 root 20 0 0 0 0 I 0.0 0.0 0:00.00 kworker/6:0-events 54 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 kworker/6:0H-events_highpri 55 root 20 0 0 0 0 S 0.0 0.0 0:00.00 cpuhp/7 root@Ubuntu-2204-jammy-amd64-base ~ # df -h
Filesystem Size Used Avail Use% Mounted on
tmpfs 6.3G 796K 6.3G 1% /run
/dev/sda3 407G 2.1G 384G 1% /
tmpfs 32G 0 32G 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
/dev/sda2 975M 134M 791M 15% /boot
tmpfs 6.3G 0 6.3G 0% /run/user/0
root@Ubuntu-2204-jammy-amd64-base ~ # curl -sL yabs.sh | bash
# ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## #
# Yet-Another-Bench-Script #
# v2023-04-23 #
# https://github.com/masonr/yet-another-bench-script #
# ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## #
Sun Jun 4 10:10:30 PM CEST 2023
Basic System Information:
---------------------------------
Uptime : 0 days, 0 hours, 1 minutes
Processor : Intel(R) Xeon(R) CPU E3-1275 v5 @ 3.60GHz
CPU cores : 8 @ 3600.000 MHz
AES-NI : ✔ Enabled
VM-x/AMD-V : ✔ Enabled
RAM : 62.6 GiB
Swap : 32.0 GiB
Disk : 407.4 GiB
Distro : Ubuntu 22.04.2 LTS
Kernel : 5.15.0-71-generic
VM Type : NONE
IPv4/IPv6 : ✔ Online / ✔ Online
IPv6 Network Information:
---------------------------------
ISP : Hetzner Online GmbH
ASN : AS24940 Hetzner Online GmbH
Host : Hetzner
Location : Falkenstein, Saxony (SN)
Country : Germany
fio Disk Speed Tests (Mixed R/W 50/50):
---------------------------------
Block Size | 4k (IOPS) | 64k (IOPS)
------ | --- ---- | ---- ----
Read | 40.86 MB/s (10.2k) | 199.66 MB/s (3.1k)
Write | 40.94 MB/s (10.2k) | 200.71 MB/s (3.1k)
Total | 81.80 MB/s (20.4k) | 400.37 MB/s (6.2k)
| |
Block Size | 512k (IOPS) | 1m (IOPS)
------ | --- ---- | ---- ----
Read | 316.62 MB/s (618) | 300.09 MB/s (293)
Write | 333.45 MB/s (651) | 320.08 MB/s (312)
Total | 650.07 MB/s (1.2k) | 620.18 MB/s (605)
iperf3 Network Speed Tests (IPv4):
---------------------------------
Provider | Location (Link) | Send Speed | Recv Speed | Ping
----- | ----- | ---- | ---- | ----
Clouvider | London, UK (10G) | 781 Mbits/sec | 933 Mbits/sec | 19.9 ms
Scaleway | Paris, FR (10G) | 785 Mbits/sec | 928 Mbits/sec | 24.6 ms
NovoServe | North Holland, NL (40G) | 788 Mbits/sec | 937 Mbits/sec | 11.8 ms
Uztelecom | Tashkent, UZ (10G) | 749 Mbits/sec | 610 Mbits/sec | 92.2 ms
Clouvider | NYC, NY, US (10G) | 738 Mbits/sec | 93.5 Mbits/sec | 86.9 ms
Clouvider | Dallas, TX, US (10G) | 711 Mbits/sec | 361 Mbits/sec | 123 ms
Clouvider | Los Angeles, CA, US (10G) | 692 Mbits/sec | 336 Mbits/sec | 150 ms
iperf3 Network Speed Tests (IPv6):
---------------------------------
Provider | Location (Link) | Send Speed | Recv Speed | Ping
----- | ----- | ---- | ---- | ----
Clouvider | London, UK (10G) | 776 Mbits/sec | 914 Mbits/sec | 19.9 ms
Scaleway | Paris, FR (10G) | 778 Mbits/sec | busy | 24.7 ms
NovoServe | North Holland, NL (40G) | 781 Mbits/sec | 923 Mbits/sec | 11.8 ms
Uztelecom | Tashkent, UZ (10G) | 740 Mbits/sec | 687 Mbits/sec | 92.0 ms
Clouvider | NYC, NY, US (10G) | 597 Mbits/sec | 152 Mbits/sec | 87.9 ms
Clouvider | Dallas, TX, US (10G) | 704 Mbits/sec | 289 Mbits/sec | 123 ms
Clouvider | Los Angeles, CA, US (10G) | 687 Mbits/sec | 322 Mbits/sec | 150 ms
Geekbench 6 Benchmark Test:
---------------------------------
Test | Value
|
Single Core | 1358
Multi Core | 4520
Full Test | https://browser.geekbench.com/v6/cpu/1482576
YABS completed in 12 min 2 sec
root@Ubuntu-2204-jammy-amd64-base ~ #