How to automate FTP transfers in Linux Shell Scripting

https://blog.eduonix.com/shell-scripting/how-to-automate-ftp-transfers-in-linux-shell-scripting/

The heredocs
We are going to use a bash feature called “here documents” or heredocs. The main use of this feature is to enable entering multiple lines of input into an interactive prompt. It starts with any string preceded by << (Example <<EOF), then you add the commands line by line, finally you end the block by adding the same string you used, but on a new line and without the << (Example EOF).
To give you a more illustrated idea about heredocs, consider this example:
The echo command may be fine if you want to output a single line of text to the screen. But what if you want to output a number of lines? You can use cat with heredocs as follows:

cat <<EOT
This is line 1
This is line 2
Thanks
EOT

And the output of this would be:

This is line 1
This is line 2
Thanks

The idea here is feeding the command with a block of lines and forcing it to treat them as a single argument. So how can this be useful to our FTP automation task? It’s the same concept: FTP is expecting a command as an argument (like user username password), that will be followed by a number of get, put and other FTP commands.

 

#!/bin/bash

HOST=ftp.example.com
USER=ftpuser
PASSWORD=P@ssw0rd

ftp -inv $HOST <<EOF
user $USER $PASSWORD
cd /path/to/file
mput *.html
bye
EOF

 

Advertisements
Posted in linux | Tagged , , | Leave a comment

Linux Configure Keyboard in Console

To change the keyboard layout you have to change

  1. Yast keyboard
  2. xWindows keyboard

1. Change the YaST Keyboard

cat /etc/sysconfig/keyboard

YAST_KEYBOARD=”english-uk,pc104″

https://wiki.archlinux.org/index.php/Keyboard_configuration_in_console

Keyboard mappings (keymaps) for virtual console, console fonts and console maps are provided by the kbd package (a dependency of systemd), which also provides many low-level tools for managing virtual console. In addition, systemd also provides the localectl tool, which can control both the system locale and keyboard layout settings for both the virtual console and Xorg.

Contents

Viewing keyboard settings

Use localectl status to view the current keyboard configurations.

Setting keyboard layout

Keymap codes

Usually one keymap file corresponds to one keyboard layout (the include statement can be used to share common parts and a keymap file can contain multiple layouts with some key combination used for switching). The keymap files are stored in the /usr/share/kbd/keymaps/ directory tree.

The naming conventions of console keymaps are somewhat arbitrary, but usually they are based on:

For a list of all the available keymaps, use the command:

$ localectl list-keymaps

To search for a keymap, use the following command, replacing search_term with the code for your language, country, or layout:

$ localectl list-keymaps | grep -i search_term

Alternatively, using find:

$ find /usr/share/kbd/keymaps/ -type f

Persistent configuration

A persistent keymap can be set in /etc/vconsole.conf, which is read by systemd on start-up. The KEYMAP variable is used for specifying the keymap. If the variable is empty or not set, the us keymap is used as default value. See vconsole.conf(5) for all options. For example:

/etc/vconsole.conf
KEYMAP=uk
...

For convenience, localectl may be used to set console keymap. It will change the KEYMAP variable in /etc/vconsole.conf and also set the keymap for current session:

$ localectl set-keymap --no-convert keymap

The --no-convert option can be used to prevent localectl from automatically changing the Xorg keymap to the nearest match. See localectl(1) for more information.

Temporary configuration

It is possible to set a keymap just for current session. This is useful for testing different keymaps, solving problems etc.

The loadkeys tool is used for this purpose, it is used internally by systemd when loading the keymap configured in /etc/vconsole.conf. It can be used very simply for this purpose:

# loadkeys keymap

See loadkeys(1) details.

Adjusting typematic delay and rate

The typematic delay indicates the amount of time (typically in miliseconds) a key needs to be pressed and held in order for the repeating process to begin. After the repeating process has been triggered, the character will be repeated with a certain frequency (usually given in Hz) specified by the typematic rate. These values can be changed using the kbdrate command. Note that these settings are configured seperately for the virtual console and for Xorg.

# kbdrate [-d delay] [-r rate]

For example to set a typematic delay to 200ms and a typematic rate to 30Hz, use the following command:

# kbdrate -d 200 -r 30

Issuing the command without specifying the delay and rate will reset the typematic values to their respective defaults; a delay of 250ms and a rate of 11Hz:

# kbdrate

Systemd service

A systemd service can be used to set the keyboard rate. For example

/etc/systemd/system/kbdrate.service
[Unit]
Description=Keyboard repeat rate in tty.

[Service]
Type=oneshot
RemainAfterExit=yes
StandardInput=tty
StandardOutput=tty
ExecStart=/usr/bin/kbdrate -s -d 450 -r 60
 
[Install]
WantedBy=multi-user.target

Then start/enable the kbdrate.service systemd service.

 

2. Change the keyboard layout in the x server configuration

## Linux: change the keyboard layout from the console
## https://benohead.com/linux-change-the-keyboard-layout-from-the-console/
sudo loadkeys uk

In a text console you can use (requires root permission, use sudo if available)
For a uk keyboard run in the console:
loadkeys uk
The keymap names are in /lib/kbd/keymaps, eg uk keyboard map is /lib/kbd/keymaps/i386/qwerty/uk.map.gz
In xwindows you can use:
setxkbmap -layout gb
where gb = great britain, uk = united kingdom , but they’re the same keyboards, use “es” for spanish etc. can also add “-model pc105” type options to setxkbmap command.

## https://wiki.archlinux.org/index.php/Xinit
Edit $HOME/.Xkbmap and insert setxkbmap -layout gb
vi $HOME/.Xkbmap
##Insert:
setxkbmap -layout gb

## grub parameters vconsole.keytable
## https://docs.oracle.com/cd/E52668_01/E54669/html/section_a43_3bk_q4.html
4.6 Modifying Kernel Boot Parameters in GRUB 2

To modify the boot parameters in the GRUB 2 configuration so that they are applied by default at every reboot:

Edit /etc/default/grub and modify the parameters in the GRUB_CMDLINE_LINUX definition, for example:

GRUB_CMDLINE_LINUX=”vconsole.font=latarcyrheb-sun16 vconsole.keymap=uk
crashkernel=auto rd.lvm.lv=ol/swap rd.lvm.lv=ol/root biosdevname=0
rhgb quiet systemd.unit=runlevel3.target”

This example adds the parameter systemd.unit=runlevel3.target so that the system boots into multi-user, non-graphical mode by default.

Rebuild /boot/grub2/grub.cfg:

# grub2-mkconfig -o /boot/grub2/grub.cfg

The change takes effect for subsequent system reboots of all configured kernels.

Reference
https://linux.die.net/man/1/setxkbmap
https://wiki.archlinux.org/index.php/Xinit

Posted in linux | Tagged , | Leave a comment

Delete the Core Dump Files on Linux

From https://lists.opensuse.org/opensuse/2016-12/msg00052.html

 

linux-31cz:~ # cd /var/lib/systemd/coredump
linux-31cz:/var/lib/systemd/coredump # ls -al
total 1564
drwxr-xr-x 1 root root 1168 Mar 21 16:15 .
drwxr-xr-x 1 root root 104 Jan 18 12:37 ..
-rw-r-----+ 1 root root 1353928 Mar 20 15:57 core.Microsoft\x2eVSCod.1000.11f2d1fbf8054bff8ddb50ac88599352.4968.1521554204000000.xz
-rw-r-----+ 1 root root 39624 Mar 21 15:14 core.smoquerysample.1000.11f2d1fbf8054bff8ddb50ac88599352.26120.1521638074000000.xz
-rw-r-----+ 1 root root 39460 Mar 21 16:05 core.smoquerysample.1000.11f2d1fbf8054bff8ddb50ac88599352.27805.1521641145000000.xz
-rw-r-----+ 1 root root 39492 Mar 21 16:07 core.smoquerysample.1000.11f2d1fbf8054bff8ddb50ac88599352.27887.1521641256000000.xz
-rw-r-----+ 1 root root 39552 Mar 21 16:09 core.smoquerysample.1000.11f2d1fbf8054bff8ddb50ac88599352.27972.1521641372000000.xz
-rw-r-----+ 1 root root 39584 Mar 21 16:12 core.smoquerysample.1000.11f2d1fbf8054bff8ddb50ac88599352.28109.1521641541000000.xz
-rw-r-----+ 1 root root 39564 Mar 21 16:15 core.smoquerysample.1000.11f2d1fbf8054bff8ddb50ac88599352.28262.1521641724000000.xz
linux-31cz:/var/lib/systemd/coredump # 
linux-31cz:/var/lib/systemd/coredump # rm ./*core*
linux-31cz:/var/lib/systemd/coredump # ls -al
total 0
drwxr-xr-x 1 root root 0 Mar 21 17:50 .
drwxr-xr-x 1 root root 104 Jan 18 12:37 ..
linux-31cz:/var/lib/systemd/coredump #

 

Posted in linux | Tagged , , | Leave a comment

TSM Extend StgPool Capacity and Show Backup Objects

To extend the capacity of FCM stgpool run:

dsmadmc -node=admin

q stg

Notice the big capacity stgpool that can be used for the nextstgpool param for the little 100MB capacity FCM_SPFS stgpool.

update stg    FCM_SPFS    NEXTstgpool=IBM_DEPLOY_CLIENT_POOL

To show the FCM backup objects by versions run:

show versions NODE_FS * nametype=unicode

To show the occupacy run:

q occ NODE_FS

 

Posted in data protection | Tagged , , | Leave a comment

What size does TSM backup hold?

Run dsmadmin, and inside the TSM SQL statement:

SELECT CAST(FLOAT(SUM(bk.bfsize))/1024/1024/1024 as DEC(14,1)) as size_gb, count(bk.bfsize) as number_of_objects FROM backups b, backup_objects bk WHERE b.state='ACTIVE_VERSION' and b.object_id=bk.objid and b.node_name='node_SQL'
Posted in Uncategorized | Tagged | Leave a comment

Pass arguments to the PowerShell script in PowerShell ISE

Use the command pane. Open the script file in the ISE editor, set the breakpoints (F9). Then in the command pane type a command invoking this script with required parameters. I do not think there is another (built-in) way of doing this in ISE.

Posted in develop | Tagged , , | Leave a comment

Add a repository to SEL

Reference https://code.visualstudio.com/docs/setup/linux

Running VS Code on Linux
Installation

openSUSE and SLE based distributions

The yum repository above also works for openSUSE and SLE based systems, the following script will install the key and repository:

sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc
sudo sh -c 'echo -e "\nname=Visual Studio Code\nbaseurl=https://packages.microsoft.com/yumrepos/vscode\nenabled=1\ntype=rpm-md\ngpgcheck=1\ngpgkey=https://packages.microsoft.com/keys/microsoft.asc" > /etc/zypp/repos.d/vscode.repo'

Then update the package cache and install the package using:

sudo zypper refresh
sudo zypper install code

Run Visual code as tony user.

whereis code
# code: /usr/bin/code /usr/share/code /usr/share/man/mann/code.n.gz
code

Read more from https://code.visualstudio.com/docs?start=true

==================

 

Reference:
https://tecadmin.net/install-visual-studio-code-editor-in-suse-linux/

Step #1. Enable Package Repository

Create a new file /etc/zypp/repos.d/vscode.repo and edit in text editor. Now add following content to the file.

[vscode]
name=Visual Studio Code
baseurl=https://packages.microsoft.com/yumrepos/vscode
enabled=1
type=rpm-md
gpgcheck=1
gpgkey=https://packages.microsoft.com/keys/microsoft.asc

Step #2. Install Visual Studio Code

Now, Import the package signing gpg key on your system using the following command.

sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc

After importing gpg key, let’s use below commands to install Visual Code on your openSUSE or SEL system.

tony@linux-31cz:~/SqlToolsService>

sudo zypper refresh

 #Repository 'SDK12-SP2 12.2-0' is up to date.
 #Repository 'SLES12-SP2-12.2-0' is up to date.
 #Repository 'ibm_sles12sp2' is up to date.
 #Repository 'packages-microsoft-com-mssql-server-2017' is up to date.
 #Repository 'packages-microsoft-com-prod' is up to date.
 #Repository 'Visual Studio Code' is up to date.
 #All repositories have been refreshed.
sudo zypper install code
 Loading repository data...
 Reading installed packages...
 Resolving package dependencies...

The following NEW package is going to be installed:
 code

The following package has no support information from it's vendor:
 code

1 new package to install.
 Overall download size: 65.1 MiB. Already cached: 0 B. After the operation, additional 191.9 MiB will be used.
 Continue? [y/n/...? shows all options] (y): y
 Retrieving package code-1.19.3-1516876593.el7.x86_64 (1/1), 65.1 MiB (191.9 MiB unpacked)
 Retrieving: code-1.19.3-1516876593.el7.x86_64.rpm ............................................................[error]
 Download (curl) error for 'https://packages.microsoft.com/yumrepos/vscode/code-1.19.3-1516876593.el7.x86_64.rpm':
 Error code: Connection failed
 Error message: Failed to connect to packages.microsoft.com port 443: Connection refused

Abort, retry, ignore? [a/r/i/...? shows all options] (a): r
 Abort, retry, ignore? [a/r/i/...? shows all options] (a): r
 Retrieving: code-1.19.3-1516876593.el7.x86_64.rpm ............................................................[error]
 Download (curl) error for 'https://packages.microsoft.com/yumrepos/vscode/code-1.19.3-1516876593.el7.x86_64.rpm':
 Error code: Connection failed
 Error message: Failed to connect to packages.microsoft.com port 443: Connection refused

Abort, retry, ignore? [a/r/i/...? shows all options] (a): r
 Abort, retry, ignore? [a/r/i/...? shows all options] (a): r
 Retrieving: code-1.19.3-1516876593.el7.x86_64.rpm ---------------------------------------------------------[starting]Retrieving: code-1.19.3-1516876593.el7.x86_64.rpm ............................................................[error]
 Download (curl) error for 'https://packages.microsoft.com/yumrepos/vscode/code-1.19.3-1516876593.el7.x86_64.rpm':
 Error code: Connection failed
 Error message: Failed to connect to packages.microsoft.com port 443: Connection refused

Abort, retry, ignore? [a/r/i/...? shows all options] (a): r
 Invalid answer 'rr'. [a/r/i/...? shows all options] (a): r
 Abort, retry, ignore? [a/r/i/...? shows all options] (a): r
 Retrieving: code-1.19.3-1516876593.el7.x86_64.rpm .................................................[done (3.6 MiB/s)]
 Checking for file conflicts: ..................................................................................[done]
 (1/1) Installing: code-1.19.3-1516876593.el7.x86_64 ...........................................................[done]
 tony@linux-31cz:~/SqlToolsService>

 

Step #3. Open Visual Studio Code

Now launch the Visual Studio Code editor on your system using graphical menu. After that create new file or open files and directories using File menu.

Step #4. Add Required Extensions

There are a large number of extensions available for Visual Studio Code like, C#, Python, JavaScript, Google Chrome etc. Install the required extensions to enhance your working experience with Visual Studio Code.

======================================================================

Update sql server, sql tools and unixODBC packages on Linux

sudo zypper update mssql-server mssql-tools unixODBC-devel

========= BELOW IT IS THE OUTPUT =====================================

tony@linux-31cz:~/SqlToolsService> sudo zypper update mssql-server
root's password:
Loading repository data...
Reading installed packages...
No update candidate for 'mssql-server-14.0.3015.40-1.x86_64'. The highest available version is already installed.
Resolving package dependencies...

Nothing to do.
tony@linux-31cz:~/SqlToolsService>

tony@linux-31cz:~/SqlToolsService> sudo zypper update mssql-tools unixODBC-devel
Download (curl) error for 'https://packages.microsoft.com/sles/12/mssql-server-2017/repodata/repomd.xml':
Error code: Connection failed
Error message: Failed to connect to packages.microsoft.com port 443: Connection refused

Abort, retry, ignore? [a/r/i/...? shows all options] (a): r
Abort, retry, ignore? [a/r/i/...? shows all options] (a): r
Download (curl) error for 'https://packages.microsoft.com/sles/12/mssql-server-2017/repodata/repomd.xml':
Error code: Connection failed
Error message: Failed to connect to packages.microsoft.com port 443: Connection refused

Abort, retry, ignore? [a/r/i/...? shows all options] (a): r
Abort, retry, ignore? [a/r/i/...? shows all options] (a): r
Download (curl) error for 'https://packages.microsoft.com/sles/12/mssql-server-2017/repodata/repomd.xml':
Error code: Connection failed
Error message: Failed to connect to packages.microsoft.com port 443: Connection refused

Abort, retry, ignore? [a/r/i/...? shows all options] (a): r
Abort, retry, ignore? [a/r/i/...? shows all options] (a): r
Loading repository data...
Reading installed packages...
No update candidate for 'unixODBC-devel-2.3.4-6.5.x86_64'. The highest available version is already installed.
No update candidate for 'mssql-tools-14.0.6.0-1.x86_64'. The highest available version is already installed.
Resolving package dependencies...

Nothing to do.
tony@linux-31cz:~/SqlToolsService>

Posted in develop, linux | Tagged , , , | Leave a comment