Keepintouchwithforanykindoftechnicalquestions
ShellScriptingforAmazonWebServicestoManageit'sresources
https://techtutorials.github.io/shell-scripting-tutorial/
FacebookEmailListLinkedinTwitterYoutubeEmailAddressWhatsAppGroupLinuxTelegramGroupRedditTechTutorialsTumblrAcompletebegineersguidetolearnshellscriptingfromscratchwhichincludesVideos,Practicescenariosandprojectidea.Iwillcreateonefileforonetopicwithcode.
BeforejumpingintotheShellscriptingbelowarecommandsyouhavetopracticeforbetterunderstandingandfamiliarwithLinuxcommandlineinterface.
Ifyoudonotlearnbelowcommandsalsofinebutipersonallyrecommendyoutolearncommandsfirst.
103LinuxCommandsVideoTutorial
aliasandunalias,arch,arp,at,awk,bc,blkid,cal,cat,cd,chage,chattr,chgrp,chmod,chown,cp,cpio,crontab,curl,cut,date,dd,df,diff,dig,dnf,du,expr,fdisk,file,find,firewall-cmd,free,ftp,grep,head,history,hostname,id,ifconfig,iostat,ip,kill,last,lessandmore,ln,locate,lpstatandlpadmin,ls,lsof,lspci,mail,man,mdadm,mkdirandrmdir,mkisofs,mount,mutt,mv,nano,netstat,nice,renice,nslookup,passwd,pam_tally2,paste,ping,perloneliner,pkill,ps,pwd,reboot,poweroff,rm,rpm,rsync,scp,screen,sed,sort,ss,ssh,sysctl,tail,tar,tcpdump,top,touch,tr,traceroute,umask,uname,uniq,uptime,useradd,vi,vmstat,w,who,watch,wc,wget,ypcat,yppasswd,yum,zip,sar
Afterthatstartlearningshellscriptingusingbelowtopics
ShellScriptingVideoTutorialShellScriptingcourseOverviewLinuxBasicsLinuxDirectoryStructureLinuxBasicCommandsCopy,Remove,MoveandTimeCommandsDifandGrepCommandsHead,tail,sortandmorecommandstrandwccommandsDiskutilitieslikefdisk,dfandducommandsGettingHelpFromCommandLineuserInterfacew,who,hostnamemhostnamectlandunamecommandsSearchforfilesanddirectoriesusingfindandlocatecommandstopcommanditsoutputexplanationvi&vimtexteditorsed,awk,vmstatandnestatcommandsvnstatcommandIntroductiontoGraphicaluserinterfacecutcommandMergemultiplefilesusingpastecommandConnectandManageremotemachineusingSSHChangingfilesanddirectorypermissionstarandzipcommandsSchedulingfuturejobsusingcrontabdifferencebetweenscriptingandprogrammingwhatisshellscriptingandit'sadvantagesPATHenvironmentvariableSymbolsusedshellscriptingMakeShellScriptTemplateQuotessingle,doubleandreverse-KnowdifferencebetweeneachBashcolorsScriptexitstatusVariablesandit'srulesSpecialVariablesEnvironmentVariables,systemvariablesanduserdefinedvariablesConstantvariables,Local&GlobalvariablesandSpecialvariablesPositionalParametersCountnumbercommandlinearguments$#ArithmeticOperatorsRelationalOperatorsLogicalOperatorsBooleanOperatorsMathsusingexprcommandRealmathsusingbccommandifstatementif-elsestatementif-else-ifstatementNestedifstatementCasestatementForLoopWhileLoopUntilLoopFunctionsArraysEvalcommandShiftingparametersusingshiftcommandIFS-InputFieldSeparatorWritingCPUUsagescriptWritingDiskUtilizationscriptTroubleshootingdebuggingshellscriptsCheckingshellscripterrorsandimprovementsusingshellcheck.netsiteHereDocumenttowriteparagraphsoftextGetoptsFunctionExecutingMultiplescriptsfromsinglescriptloggerloggingmessagestologfileResourcetoDownload
ShellScriptingBookShellScriptingBookShellScriptingBookShellScriptingBookWriteYourOwnMethodofScriptforbelowScenario
Scenario:EverydayfromMondaytoFridayonedirectorywillbecreatedunder/fullbackup/dailybackup/YYYY-MM-DDanditwillmovebackuptoitsparentdirectoryeverydaymidnight/fullbackup/archive/,HoweverSaturday,SundayandMondaydirectorieswillmoveto/fullbackup/archivepatheverymondayevening.
DirectoryNamesExample:2018-12-242018-12-252018-12-262018-12-272018-12-28
Question:Iwouldliketodeletedirectoriesolderthantwodaysfrom/fullbackup/archivepath.Howdoyoudoitusinganyscriptingmethods.
ProblemStatement:Iwastryingtousefind/path/-typed-mtime+2-print0|xargs-r0rm--.ThiscommanddoesnotworkasexpectedduetodirectorymodifieddateforSAT,SUNandMONmoveddirectoriessameforallasMondaydate.
HowDoyousolveit.??WriteShellScripttoaccomplishthistask.Shouldrunthroughcrontabandcleardirectoriesolderthantwodays.
评论