获取虚拟机运行时长的脚本

复制代码
#!/bin/bash

# 获取虚拟机启动时间戳
boot_timestamp=$(date -d "$(uptime -s)" +%s)

# 当前时间戳
current_timestamp=$(date +%s)

# 计算运行时长(以秒为单位)
runtime=$((current_timestamp - boot_timestamp))

# 将运行时长转换为可读格式
days=$((runtime / 86400))
hours=$(( (runtime % 86400) / 3600 ))
minutes=$(( (runtime % 3600) / 60 ))
seconds=$((runtime % 60))

# 打印运行时长
echo "虚拟机已运行:$days 天 $hours 小时 $minutes 分钟 $seconds 秒"
复制代码

 

posted @   吃吃吃大王  阅读(89)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
点击右上角即可分享
微信分享提示