2022年12月18日 星期日

RDP to Ubuntu desktop

Reference:
 
apt install xfce4 xrdp
systemctl enable xrdp
adduser xrdp ssl-cert
vi /etc/xrdp/startwm.sh
新增紅色部分
 
if test -r /etc/profile; then
        . /etc/profile
fi

startxfce4
test -x /etc/X11/Xsession && exec /etc/X11/Xsession
exec /bin/sh /etc/X11/Xsession
 
重新啟動service
systemctl restart xrdp
 
修改登入帳號user1的 .xsession
su - user1
echo xfce4-session > ~/.xsession
 
PS. GNOME desktop沒測試出來

Ubuntu 22.04.1 install ssh server

Reference:
Ubuntu 安裝與設定 ssh server
 
Ubuntu 22.04.1預設沒有 sshd,安裝指令:
apt install openssh-server -y

確認sshd運行狀況:
systemctl status ssh

如果要讓root可以用ssh連上:
vi /etc/ssh/sshd_config
加上 PermitRootLogin yes
systemctl restart ssh

2022年12月2日 星期五

CentOS Gnome xwindow 縮小後消失的處理方法

Reference:

狀況:
xwindow 縮小後消失

解法:
Right-click on the "task bar", click "Add to Panel", select "Window List" and "Add". 


2022年10月7日 星期五

Run powershell with TaskSchd 工作排程器

Reference:
 
在工作排程器執行 powershell,不能直接指定 ps1 檔案。
 
設定方法:
需要在「程式或指令碼」打powershell
「新增引數」打-file “C:\script\import.ps1” 才能正常運行
 
2024/10/23 update:
如果要把output & error 輸出到檔案,「新增引數」打-file “C:\script\import.ps1 *> log.txt”

Reference: 

2022年10月3日 星期一

Powershell Script for Microsoft SQL server

Reference:
 
#連線資料庫
$serverName = "SQL01"
$databaseName = "wiside"
$tableName = "dbo.raw_data"
$uid = 'sa'
$pwd = 'mypassword'

$Connection = New-Object System.Data.SQLClient.SQLConnection
$Connection.ConnectionString = "server='$serverName';database='$databaseName';User ID = $uid; Password = $pwd;"
$Connection.Open()
$Command = New-Object System.Data.SQLClient.SQLCommand
$Command.Connection = $Connection

$insertquery="INSERT INTO $tableName ([ID],[mac],[vendor],[datetime]) VALUES ('$ID','$mac','$vendor','$datetime')"
$Command.CommandText = $insertquery
$Command.ExecuteNonQuery()

$Connection.Close();

catch exception on powershell script

Reference: 

try {
    # 主要程式邏輯
}
catch [System.NotSupportedException] {
    Write-Output "不支援"
}
catch [System.IO.DirectoryNotFoundException] {
    Write-Output "找不到資料夾"
}
catch {
    Write-Output "通用的例外處理"
}

LInux samba service on CentOS 7

Reference:
 
安裝:
yum install -y samba

設定:
cp /etc/samba/smb.conf /etc/samba/smb.conf.ori
vi /etc/samba/smb.conf
 
[global]
        workgroup = SAMBA
        security = user
        #passdb backend = tdbsam

        map to guest = bad user
        #printing = cups
        #printcap name = cups
        #load printers = yes
        #cups options = raw

[images]
        comment = public images
        path = /path/to/images
        browseable = Yes
        read only = Yes
        writable = Yes
        guest ok = Yes
        force user = smbuser
 
啟動:
systemctl enable smb.service ; systemctl enable nmb.service
systemctl restart smb.service ; systemctl restart nmb.service
 
設定使用者帳號:
user add smbuser
smbpasswd smbuser
chown -R smbuser /path/to/images