In the daily standup, it was noted that the timezone settings across the Nautilus Application Servers in the Stratos Datacenter are inconsistent with the local datacenter's timezone, currently set to America/Blanc-Sablon.
Synchronize the timezone settings to match the local datacenter's timezone (America/Blanc-Sablon)
Table of Contents
- Prerequisites
- Manual Configuration Steps
- Automated One-Line Commands
- Complete Script Implementation
- Verification Procedures
- Alternative Methods
- Troubleshooting Guide
- Timezone Information
Prerequisites
- SSH access to all application servers
- Sudo privileges on each server
- Server credentials:
- stapp01: User
tony/ PasswordIr0nM@n - stapp02: User
steve/ PasswordAm3ric@ - stapp03: User
banner/ PasswordBigGr33n
- stapp01: User
Manual Configuration Steps
Step 1: Connect to Each Application Server
# App Server 1
ssh tony@stapp01
# App Server 2
ssh steve@stapp02
# App Server 3
ssh banner@stapp03
Step 2: Check Current Timezone
# Using timedatectl
timedatectl
# Using date command
date
# Check timezone configuration file
cat /etc/timezone 2>/dev/null || cat /etc/sysconfig/clock 2>/dev/null
Step 3: Set Timezone to America/Blanc-Sablon
Method 1: Using timedatectl (Recommended)
sudo timedatectl set-timezone America/Blanc-Sablon
Method 2: Using Symbolic Link
sudo ln -sf /usr/share/zoneinfo/America/Blanc-Sablon /etc/localtime
Method 3: Using tzdata (Debian/Ubuntu)
echo "America/Blanc-Sablon" | sudo tee /etc/timezone
sudo dpkg-reconfigure --frontend noninteractive tzdata
Step 4: Verify the Change
# Check updated timezone
timedatectl
# Verify with date command
date
# Check symbolic link
ls -la /etc/localtime
# Verify timezone file
cat /etc/timezone 2>/dev/null || cat /etc/sysconfig/clock 2>/dev/null
# Detailed status
timedatectl status
Step 5: Exit the Server
exit
Automated One-Line Commands
Complete Commands for All Servers
# stapp01
echo 'Ir0nM@n' | ssh tony@stapp01 "sudo -S bash -c 'timedatectl set-timezone America/Blanc-Sablon && timedatectl | grep \"Time zone\"'"
# stapp02
echo 'Am3ric@' | ssh steve@stapp02 "sudo -S bash -c 'timedatectl set-timezone America/Blanc-Sablon && timedatectl | grep \"Time zone\"'"
# stapp03
echo 'BigGr33n' | ssh banner@stapp03 "sudo -S bash -c 'timedatectl set-timezone America/Blanc-Sablon && timedatectl | grep \"Time zone\"'"
Why This Syntax Works
The command uses sudo -S bash -c 'cmd1 && cmd2' to pass the password once and execute multiple commands within a single sudo session. This avoids the issue where only the first sudo command receives the password.
Using Heredoc (More Detailed Output)
# stapp01
ssh tony@stapp01 << 'EOF'
echo 'Ir0nM@n' | sudo -S bash -c '
echo "Current timezone:"
timedatectl | grep "Time zone"
echo ""
echo "Setting timezone to America/Blanc-Sablon..."
timedatectl set-timezone America/Blanc-Sablon
echo ""
echo "New timezone:"
timedatectl | grep "Time zone"
echo ""
date
'
EOF
# stapp02
ssh steve@stapp02 << 'EOF'
echo 'Am3ric@' | sudo -S bash -c '
echo "Current timezone:"
timedatectl | grep "Time zone"
echo ""
echo "Setting timezone to America/Blanc-Sablon..."
timedatectl set-timezone America/Blanc-Sablon
echo ""
echo "New timezone:"
timedatectl | grep "Time zone"
echo ""
date
'
EOF
# stapp03
ssh banner@stapp03 << 'EOF'
echo 'BigGr33n' | sudo -S bash -c '
echo "Current timezone:"
timedatectl | grep "Time zone"
echo ""
echo "Setting timezone to America/Blanc-Sablon..."
timedatectl set-timezone America/Blanc-Sablon
echo ""
echo "New timezone:"
timedatectl | grep "Time zone"
echo ""
date
'
EOF
Complete Script Implementation
Create a script file named set_timezone.sh:
#!/bin/bash
# Define servers with their credentials
declare -A SERVERS=(
["stapp01"]="tony:Ir0nM@n"
["stapp02"]="steve:Am3ric@"
["stapp03"]="banner:BigGr33n"
)
TIMEZONE="America/Blanc-Sablon"
echo "========================================="
echo "Synchronizing Timezone to $TIMEZONE"
echo "========================================="
for server in "${!SERVERS[@]}"; do
IFS=':' read -r user pass <<< "${SERVERS[$server]}"
echo ""
echo "-----------------------------------------"
echo "Processing $server (User: $user)"
echo "-----------------------------------------"
sshpass -p "$pass" ssh -o StrictHostKeyChecking=no "$user@$server" "sudo -S bash -c '
echo \"Current timezone:\"
timedatectl | grep \"Time zone\"
echo \"Setting timezone to $TIMEZONE...\"
timedatectl set-timezone $TIMEZONE
echo \"New timezone:\"
timedatectl | grep \"Time zone\"
echo \"Current date and time:\"
date
'"
if [ $? -eq 0 ]; then
echo "SUCCESS: $server completed successfully"
else
echo "ERROR: Failed to configure $server"
fi
done
echo ""
echo "========================================="
echo "All App servers timezone synchronized"
echo "========================================="
echo ""
echo "Verification Commands:"
echo " ssh tony@stapp01 'timedatectl | grep Time zone'"
echo " ssh steve@stapp02 'timedatectl | grep Time zone'"
echo " ssh banner@stapp03 'timedatectl | grep Time zone'"
Make the script executable and run:
chmod +x set_timezone.sh
./set_timezone.sh
Alternative Script Without sshpass
If sshpass is not available, use this version:
#!/bin/bash
TIMEZONE="America/Blanc-Sablon"
echo "========================================="
echo "Synchronizing Timezone to $TIMEZONE"
echo "========================================="
# stapp01
echo ""
echo "=== stapp01 ==="
ssh tony@stapp01 << 'EOF'
echo 'Ir0nM@n' | sudo -S bash -c '
echo "Setting timezone...";
timedatectl set-timezone America/Blanc-Sablon;
echo "Verification:";
timedatectl | grep "Time zone"
'
EOF
# stapp02
echo ""
echo "=== stapp02 ==="
ssh steve@stapp02 << 'EOF'
echo 'Am3ric@' | sudo -S bash -c '
echo "Setting timezone...";
timedatectl set-timezone America/Blanc-Sablon;
echo "Verification:";
timedatectl | grep "Time zone"
'
EOF
# stapp03
echo ""
echo "=== stapp03 ==="
ssh banner@stapp03 << 'EOF'
echo 'BigGr33n' | sudo -S bash -c '
echo "Setting timezone...";
timedatectl set-timezone America/Blanc-Sablon;
echo "Verification:";
timedatectl | grep "Time zone"
'
EOF
echo ""
echo "========================================="
echo "All App servers timezone synchronized"
echo "========================================="
Verification Procedures
Verify Timezone on Each Server
# stapp01
ssh tony@stapp01 "echo 'Ir0nM@n' | sudo -S timedatectl | grep 'Time zone'"
# stapp02
ssh steve@stapp02 "echo 'Am3ric@' | sudo -S timedatectl | grep 'Time zone'"
# stapp03
ssh banner@stapp03 "echo 'BigGr33n' | sudo -S timedatectl | grep 'Time zone'"
Verify with Date Command
# stapp01
ssh tony@stapp01 "date"
# stapp02
ssh steve@stapp02 "date"
# stapp03
ssh banner@stapp03 "date"
Check Symbolic Links
# stapp01
ssh tony@stapp01 "ls -la /etc/localtime"
# stapp02
ssh steve@stapp02 "ls -la /etc/localtime"
# stapp03
ssh banner@stapp03 "ls -la /etc/localtime"
Combined Verification Command
echo "=== stapp01 ===" && ssh tony@stapp01 "echo 'Ir0nM@n' | sudo -S timedatectl | grep Time" && \
echo "=== stapp02 ===" && ssh steve@stapp02 "echo 'Am3ric@' | sudo -S timedatectl | grep Time" && \
echo "=== stapp03 ===" && ssh banner@stapp03 "echo 'BigGr33n' | sudo -S timedatectl | grep Time"
Expected Output
=== stapp01 ===
Time zone: America/Blanc-Sablon (AST, -0400)
=== stapp02 ===
Time zone: America/Blanc-Sablon (AST, -0400)
=== stapp03 ===
Time zone: America/Blanc-Sablon (AST, -0400)
Alternative Methods
Method 1: Using ln Command (if timedatectl unavailable)
# Remove existing link
sudo rm -f /etc/localtime
# Create new link
sudo ln -sf /usr/share/zoneinfo/America/Blanc-Sablon /etc/localtime
Method 2: Using /etc/timezone (Debian/Ubuntu)
# Set timezone
echo "America/Blanc-Sablon" | sudo tee /etc/timezone
# Update system
sudo dpkg-reconfigure --frontend noninteractive tzdata
Method 3: Using /etc/sysconfig/clock (RHEL/CentOS)
# Set timezone in config
echo 'ZONE="America/Blanc-Sablon"' | sudo tee /etc/sysconfig/clock
# Create symbolic link
sudo ln -sf /usr/share/zoneinfo/America/Blanc-Sablon /etc/localtime
Method 4: Interactive Method (tzselect)
# This is interactive, not suitable for automation
tzselect
# Follow prompts to select America -> Blanc-Sablon
Method 5: With NTP Sync
# If NTP is enabled, timezone change may trigger time sync
sudo timedatectl set-timezone America/Blanc-Sablon
sudo timedatectl set-ntp true
sudo timedatectl set-timezone America/Blanc-Sablon
Troubleshooting Guide
Issue 1: "Failed to set timezone: Invalid timezone"
Solution: Verify the timezone exists in the system:
timedatectl list-timezones | grep -i blanc-sablon
# Should show: America/Blanc-Sablon
Issue 2: "Permission denied"
Solution: Use sudo or become root:
sudo timedatectl set-timezone America/Blanc-Sablon
Issue 3: "System has not been booted with systemd"
Solution: Use the ln command method instead:
sudo ln -sf /usr/share/zoneinfo/America/Blanc-Sablon /etc/localtime
Issue 4: Password not accepted in one-liner
Solution: Ensure the correct syntax with single sudo session:
# Incorrect - only first sudo gets password
echo 'pass' | sudo -S cmd1 && sudo -S cmd2
# Correct - single sudo session
echo 'pass' | sudo -S bash -c 'cmd1 && cmd2'
Issue 5: Time not updating after timezone change
Solution: Restart systemd-timesyncd or force time sync:
# Restart time synchronization service
sudo systemctl restart systemd-timesyncd
# Or force time sync
sudo timedatectl set-ntp false
sudo timedatectl set-ntp true
Issue 6: Multiple verification methods
# Check from multiple sources
timedatectl
date
cat /etc/timezone 2>/dev/null
cat /etc/sysconfig/clock 2>/dev/null
ls -la /etc/localtime
Issue 7: sshpass not installed
Solution: Install sshpass or use heredoc method:
# Install sshpass
sudo yum install -y sshpass # RHEL/CentOS
sudo apt-get install -y sshpass # Ubuntu/Debian
Timezone Information
America/Blanc-Sablon Details
- Full Name: America/Blanc-Sablon
- Standard Time: AST (Atlantic Standard Time)
- UTC Offset: UTC-4
- Daylight Saving Time: No DST observed
- Location: Blanc-Sablon, Quebec, Canada
- Major Cities: Blanc-Sablon, Quebec
Timezone Comparison
| Timezone | UTC Offset | DST |
|---|---|---|
| America/Blanc-Sablon | UTC-4 | No |
| America/New_York | UTC-4/UTC-5 | Yes |
| America/Chicago | UTC-5/UTC-6 | Yes |
| America/Denver | UTC-6/UTC-7 | Yes |
| America/Los_Angeles | UTC-7/UTC-8 | Yes |
Summary
The timezone settings have been successfully synchronized on all Nautilus Application Servers:
- stapp01: Timezone set to America/Blanc-Sablon
- stapp02: Timezone set to America/Blanc-Sablon
- stapp03: Timezone set to America/Blanc-Sablon
All servers now have consistent timezone settings matching the local datacenter's timezone (America/Blanc-Sablon). Verification has been completed using timedatectl and date commands, and the timezone symbolic links have been updated accordingly.
Quick Reference Card
Manual Setup
# Connect and set timezone
ssh tony@stapp01
sudo timedatectl set-timezone America/Blanc-Sablon
timedatectl
exit
One-Line Commands
# stapp01
echo 'Ir0nM@n' | ssh tony@stapp01 "sudo -S bash -c 'timedatectl set-timezone America/Blanc-Sablon && timedatectl | grep \"Time zone\"'"
# stapp02
echo 'Am3ric@' | ssh steve@stapp02 "sudo -S bash -c 'timedatectl set-timezone America/Blanc-Sablon && timedatectl | grep \"Time zone\"'"
# stapp03
echo 'BigGr33n' | ssh banner@stapp03 "sudo -S bash -c 'timedatectl set-timezone America/Blanc-Sablon && timedatectl | grep \"Time zone\"'"
Verification
# Quick verification
ssh tony@stapp01 "echo 'Ir0nM@n' | sudo -S timedatectl | grep Time"
ssh steve@stapp02 "echo 'Am3ric@' | sudo -S timedatectl | grep Time"
ssh banner@stapp03 "echo 'BigGr33n' | sudo -S timedatectl | grep Time"
Top comments (0)