- Details
- Written by: Stanko Milosev
- Category: Linux
- Hits: 10443
Just few things which I learned.
Array:
myList="a b c d";
myListAry=${myList[@]}
for my in $myListAry; do
echo $my;
done
No spaces at sign of equality when assigning a value to variable.
Instead of quotes you can use parentheses also, but in that case I was receiving some stupid error from Grunt:
Syntax error: "(" unexpected (expecting "}")
Also, in my case this example also works (without array):
myList="a b c d";
for my in $myList; do
echo $my;
done
I had to do it without converting to array, because in the Grunt I was receiving error:
"Bad substitution"
Those two examples you can download from here. To test it, save it in a folder, lets say in Downloads, go to that folder:
cd Downloads
Load file:
. ./bash.sh
execute either:
exampleWithoutArray
or:
exampleWithArray
To replace string in a (same) file:
sed -i.bak 's/"'$my'"/"someString"/g' /home/stanko/someFile.txt
Notice that I was using double quotes, because lets assume that in your file you want "someString" replace with my variable but to have quotes. Under single quotes dollar sign ($) is not recognized, that is why I had to "close" quotes.
Switch -i means that I want to replace string in a same file.
Also, when I was loading bash script from terminal window, it seems that variables are populated like global, just once and never again, that is why I had to close terminal window, open it again, and again to load my script, otherwise my changes inside of variables would not be visible....
To comment block, use something like this:
#!/bin/bash
echo before comment
: <<'END'
bla bla
blurfl
END
echo after comment
Copy/pasted from here.
- Details
- Written by: Stanko Milosev
- Category: Linux
- Hits: 2495
Example of generatin
- Details
- Written by: Stanko Milosev
- Category: Ubuntu
- Hits: 550
apt - Advanced Package Tool (APT) is a free-software user interface that works with core libraries to handle the installation and removal of software on Debian and Debian-based Linux distributions.
systemd status - determine the status of a service
nano - a simple terminal-based text editor
lsb_release - print distribution specific information
openssh-server - collection of tools for remotely controlling networked computers. Example:
sudo apt install openssh-server sudo systemctl enable --now ssh
pipeline ‘|’ or ‘|&’ - a sequence of one or more commands separated by one of the control operators.
grep - grep searches one or more input files for lines containing a match to a specified pattern. Example:
php -m | grep -i mysql
groupadd - create a new group
useradd - create a new user or update default new user information
ls - list directory contents. Example, check owner group and permissions of a file:
ls -l /myFolder/myJson.json
chown - change file owner and group. Example, change owner to myOwner, and group to myGroup:
sudo chown myOwner:myGroup /var/www/html/kanaloa/config.json
chmod - change access permissions. Example owner = 6 - read+write, group = 6 - read+write, all other = 4 - only read:
sudo chmod 664 /var/www/html/kanaloa/config.json
> - before a command is executed, its input and output may be redirected using a special notation interpreted by the shell.
find - find files. Example:
sudo find / -type f -name "dovecot-sql.conf" 2>/dev/null
-
find /— search starting from the root/, so essentially the whole filesystem. -
-type f— search only for files. -
-name "dovecot-sql.conf"— look for exactly this filename. -
2>/dev/null— redirection to hide permission-denied and other error messages.
wget - software package for retrieving files using HTTP, HTTPS, FTP and FTPS
tar - provides the ability to create and extract tar archives
mv - move (rename) files
composer - a dependency manager for PHP
rm - remove files or directories
ln - make links between files
journalctl - print log entries from the systemd journal
- Details
- Written by: Stanko Milosev
- Category: Ubuntu
- Hits: 603
cd /var/www
sudo wget https://github.com/roundcube/roundcubemail/releases/download/1.7.2/roundcubemail-1.7.2-complete.tar.gz
sudo tar -xzf roundcubemail-1.7.2-complete.tar.gz
sudo mv roundcubemail-1.7.2 roundcube
cd roundcube
sudo chown -R www-data:www-data /var/www/roundcube
sudo find /var/www/roundcube -type d -exec chmod 755 {} \;
sudo find /var/www/roundcube -type f -exec chmod 644 {} \;
sudo chmod -R 775 /var/www/roundcube/temp
sudo chmod -R 775 /var/www/roundcube/logs
sudo mariadb
CREATE DATABASE roundcubemail CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; CREATE USER 'roundcube'@'localhost' IDENTIFIED BY 'YOUR_ROUNDCUBE_PASSWORD'; GRANT ALL PRIVILEGES ON roundcubemail.* TO 'roundcube'@'localhost'; FLUSH PRIVILEGES; EXIT;
sudo mariadb roundcubemail < /var/www/roundcube/SQL/mysql.initial.sql sudo cp config/config.inc.php.sample config/config.inc.php sudo nano config/config.inc.php
$config['enable_installer'] = true; $config['db_dsnw'] = 'mysql://roundcube:YOUR_ROUNDCUBE_PASSWORD@localhost/roundcubemail'; $config['imap_host'] = 'localhost:143'; $config['smtp_host'] = 'localhost:587'; $config['smtp_user'] = '%u'; $config['smtp_pass'] = '%p'; $config['support_url'] = ''; $config['product_name'] = 'Roundcube Webmail'; $config['des_key'] = 'GENERATE_A_RANDOM_24+_CHARACTER_SECRET_KEY'; $config['plugins'] = [ 'archive', 'zipdownload', ]; $config['skin'] = 'elastic'
openssl rand -base64 32 sudo nano /etc/nginx/sites-available/default
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
root /var/www/html;
index index.php index.html index.htm index.nginx-debian.html;
location / {
try_files $uri $uri/ =404;
}
location = /roundcube {
return 301 /roundcube/;
}
location /roundcube/ {
try_files $uri $uri/ /roundcube/index.php?$query_string;
}
location ~ ^/roundcube/(?(?:index|static|installer)\.php)(?/.*)?$ {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME /var/www/roundcube/public_html/$rc_script;
fastcgi_param SCRIPT_NAME /roundcube/$rc_script;
fastcgi_param PATH_INFO $rc_path_info;
fastcgi_pass unix:/run/php/php8.5-fpm.sock;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.5-fpm.sock;
}
}
sudo nginx -t sudo systemctl reload nginx
Open:
http://mail.myDomain.com/roundcube/sudo rm -rf /var/www/roundcube/public_html/installerand delete
$config['enable_installer'] = true;