def bash(self): spc(["bash"], shell=True) print(getcwd()) self.pwd = spc(["pwd"], shell=True) pwd_str = str(check_output( ["pwd"], shell=True, )).strip('\'' '\\b' '\\n' '\'') self.pwd_str = pwd_str self.counter = 99 self.path_dict.update({self.counter: (self.pwd_str)}) print(self.pwd_str)
def file_reader(self): self.ls_file_array = glob.glob(self.pwd_str + "/*") counter = 0 for name in self.ls_file_array: file_checker = self.ls_file_array[counter] if os.path.isfile(str(file_checker)): print(f'{counter}:{name}') if os.path.isdir(str(file_checker)): print(f'{counter}:{name}' + "(dir)") counter += 1 file_number = int(input('open file nr? or q for quit')) filename = self.ls_file_array[file_number] if os.path.isfile(filename): try: my_file = open(filename, 'r') contents = my_file.read() print(contents) except: print("no go") else: os.chdir(filename) self.pwd = spc(["pwd"]) pwd_str = str(check_output( ["pwd"], shell=True, )).strip('\'' '\\b' '\\n' '\'') self.pwd_str = pwd_str self.counter += 1 self.path_dict.update({self.counter: (self.pwd_str)})
def list_services(self): # spc("ps --no-headers") # test=check_output("ps --no-headers -o") # print(test) # spc("ps ", "--no" ,"-headers" ," -o" ," comm 1") # init_or_systemd=check_output("ps ", "--no", "-headers", " -o", "comm 1", shell=True) # print(init_or_systemd) # if init_or_systemd=="init": try: subprocess.run(["service --status-all"], shell=True) services = check_output(["service --status-all"], shell=True) print(services) except: print("you are not running init") self.linux_init = False try: spc(["systemctl --list-units"]) services2 = check_output(["systemctl --list-units"]) print(services2) except: print("running init") self.linux_init = True
def nco_exec(base_directory, site_name, date_directory, latitude, longitude): """Call the shell script that cuts out the site coordinates and concatenates with existing data (using NCO)""" exec_fpath = os.path.realpath(__file__) exec_dirpath = os.path.dirname(exec_fpath) shell_fpath = os.path.join(exec_dirpath, 'nco_shell.sh') exec_string = ('{0} "{1}" "{2}" "{3}" "{4}" "{5}"'.format( shell_fpath, base_directory, site_name, date_directory, latitude, longitude)) if spc(exec_string, shell=True): error_str = ('Exception in NCO file processing - see NCO log file for ' 'details') logging.error(error_str) raise RuntimeError('Error in command: {}'.format(exec_string)) return
def move_out_fast(self): self.cls self.move_out_str = os.chdir("/") # self.move_out_str=subprocess.call(["cd ",".."], shell=True) # self.cd self.counter += 1 self.pwd = spc(["pwd"]) pwd_str = str(check_output( ["pwd"], shell=True, )).strip('\'' '\\b' '\\n' '\'') self.pwd_str = pwd_str self.path_dict.update({self.counter: (self.pwd_str)})
def wget_exec(read_path, write_path, server_dir): """Build the complete wget string and retrieve temp continental file""" logging.info('Retrieving forecast files for date {}'.format(server_dir)) file_list = map(lambda x: '{}_{}'.format(server_dir, str(x).zfill(3)), range(7)) wget_log_path = os.path.join(base_log_path, 'ACCESS', 'Download.log') wget_prefix = '/usr/bin/wget -nv -a {} -O'.format(wget_log_path) for f in file_list: logging.info('Forecast +{} hrs'.format(str(int(f.split('_')[-1])))) tmp_fname = os.path.join(write_path, '{}_access.tmp'.format(f)) full_read_path = read_path.format('fileServer') + server_dir server_fname = os.path.join(full_read_path, 'ACCESS-R_{}_surface.nc'.format(f)) cmd = '{0} {1} {2}'.format(wget_prefix, tmp_fname, server_fname) if spc(cmd, shell=True): error_str = ('Exception in wget command execution; see wget log ' 'file for details') logging.error(error_str) raise RuntimeError(error_str)
def keyboard_input(self): menu_counter = 0 self.running = "" spc('clear') if int(self.meaning_of_life) != 42: quit() while self.running != "q": menu_counter += 1 self.write_on_the_menu = "welcome if menu is missing press <>^ once or twice followed by enter" if menu_counter == 1: self.main_menu(self.print_on_the_menu) if self.menu_needed == True: self.main_menu(self.print_on_the_menu) self.running = input() if self.running == "l": spc('clear') self.main_menu("") self.list_files() continue if self.running == "q": break if self.running == "\x1b[C": spc('clear') self.main_menu("") print(self.path_dict[self.counter]) if self.counter > 0: self.move_forward() self.list_files() continue if self.running == "\x1b[D": spc('clear') self.main_menu( "cd .. if you want more action press twice for cd /") self.move_out() self.list_files() continue if self.running == "^[[H": spc('clear') self.main_menu("home") self.home() continue if self.running == "\x1b[D\x1b[D": spc('clear') self.main_menu("cd / wow that was fast") self.move_out_fast() self.list_files() continue if self.running == "x1b[3~": print("delete key function not enabled for safetyreasons") self.main_menu("") if self.running == "open" or self.running == "o" or self.running == "\x1b[A" or self.running == "^[[A": spc('clear', shell=True) self.main_menu(self.print_on_the_menu) self.file_reader() self.menu_needed = False sleep(0.2) self.print_on_the_menu = "exiting open" self.main_menu(self.print_on_the_menu) continue if self.running == "d": spc('clear', shell=True) self.main_menu("") self.remove_file() self.main_menu("exiting delete") continue if self.running == "c": spc('clear', shell=True) self.print_on_the_menu = "WRITE A FILE NAME" self.main_menu(self.print_on_the_menu) self.create_file(self.pwd_str, (input(""))) spc('clear') self.main_menu("exiting c") continue continue if self.running == "\x1b[C\x1b[C": self.print_on_the_menu = ( "not so fast ok ok bringing you home") self.home() spc('clear') self.main_menu("exiting cd") continue if self.running == "h" or self.running == "-h" or self.running == "help": self.th_help() continue if self.running == "bash": self.bash() if self.running == "notepad" or self.running == "^[[A^[[A" or self.running == "\x1b[A\x1b[A": self.write_note() sleep(0.2) spc('clear') self.main_menu("exit notepad") continue if self.running == "ping": self.ping_a_host() if self.running == "service": self.list_services() else: spc('clear') self.main_menu(self.print_on_the_menu) self.print_on_the_menu = ( "this is a bit complicated press left,right or upp key one or twice and press enter" )
def clear_screen(self): spc(["bash"], shell=True)
spc('clear') self.main_menu("exit notepad") continue if self.running == "ping": self.ping_a_host() if self.running == "service": self.list_services() else: spc('clear') self.main_menu(self.print_on_the_menu) self.print_on_the_menu = ( "this is a bit complicated press left,right or upp key one or twice and press enter" ) spc(["clear"]) th = Terminal_helper("42") # th.change_owner() th.keyboard_input() """ Rapport till uppgift 2 i Linux och skriptspråk av Jonny Värn. Jag använder mig av VIM med plugin airline, justify, matchit, powerline och python-jedi för att få en trevlig utvecklingsmiljö med autokomplettering och lite finare vim. Jag använder mig av VIM eftersom jag sitter på en Linux konsol via ssh. Jag hade använt en annan terminalbaserad kanske emacs eftersom jag valt att inte köra grafiskt. Om jag hade kört grafiskt så hade jag antagligen kört visualstudiocode, pycharm, atom eller någon annan IDE. Jag valde filhanterare eftersom den låg på först och verkade vara den mest användbara applikationen. Filhanteraren började växa och utvecklades till Linux-terminal-helper när jag tänkte att den skulle kunna vara lite stöd för andra när de jobbar i Linux/Unix möjligtvis finns det en en framtid i windows i terminalmiljö. Linux är ju egentligen en Kärna Linux/GNU är ett operativsystem och det finns många olika varianter av GNU/Linux några av de största listas nedan. RHEL eller RedhatEnterprise där även Linus Torvalds huserar med community drivna varianter som Centos. Debian med varianter som Ubuntu som nästan har gått om Debian i antal användare. Suse Enterprise Linux som från början startade i Tyskland ursprungligen från Slackware Linux. Det alla Linux varianter delar är som sagt Linux kärnan.
userFtp = 'cocaisys' passFtp = 'mE]hX9aW6X32b+' Ru0z = 'Reporte.txt' Rs1 = 'Reporte_S1.txt' log = 'log' #carpeta uoz = 'uoz.exe'#ejecutable al llamar reIntento = 30 USER_NAME = getpass.getuser() bat_pathAD = r'C:\Users\%s\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup' % USER_NAME bat_path = r'C:\IntTFHKA' accDirect = 'AccesoRunmvl.vbs' infoERR = False #muestra Err ifExi = lambda archivo:path.exists(archivo)#si exsiste los archivo dependiente spcall = lambda exe:spc(exe, shell=False)#ejecuta subProce #spcall("""REG ADD \"HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run\" /V \"Rebootmv\" /t REG_SZ /F /D \"C:\\IntTFHKA\\runmvel.exe\"""") #Archivo registro if not path.exists(log):mk(log) logger = logging.getLogger('Monitoreo de venta mvel') logger.setLevel(logging.DEBUG) mesAnio=str(today.month)+''+str(today.year) fileLog ='log/log-%s.log'% str(mesAnio) handler = logging.handlers.TimedRotatingFileHandler(filename=fileLog, when="m", interval=1) formatter = logging.Formatter(fmt='%(asctime)s - %(name)s - %(levelname)s - %(message)s',datefmt='%d-%m-%y %H:%M:%S') handler.setFormatter(formatter) logger.addHandler(handler)