Exemple #1
0
func (c *Crontab) Read() ([]Cronjob, error) {
	sc := osutils.SystemCommand{
		Path:                 c.Path,
		Args:                 []string{"-u", c.User.Username, "-l"},
		ExecDir:              os.TempDir(),
		EnableShellExpansion: true,
	}

	output := sc.Run()
	if output.HasError() {
		nilCronjobs := []Cronjob{}
		noCrontab := fmt.Sprintf("no crontab for %s", c.User.Username)
		stdErr := strings.Trim(strings.TrimSpace(output.Stderr), "\n")

		if stdErr == noCrontab {
			return nilCronjobs, nil
		}

		return nilCronjobs, output
	}

	cp := CrontabParser{
		Buff: []byte(output.Stdout),
	}

	cronjobs, err := cp.Parse()
	if err != nil {
		return []Cronjob{}, err
	}

	return c.RemoveDuplicates(cronjobs), nil
}
Exemple #2
0
func (ag *AptGet) Run() error {
	// Check if we could use APT's native API instead of calling an external command
	// It seems we can use C++ with CGO by using Swig.
	//
	// Using the API directly would be much more efficient and less risky that
	// calling a system command which is kind of ugly.
	//
	// Interesting links:
	// http://golang.org/doc/faq#Do_Go_programs_link_with_Cpp_programs
	// http://www.swig.org/Doc2.0/Go.html

	// XXX : crap
	args := append(defaultOptions, ag.Method)
	args = stringutils.RemoveDuplicates(append(args, ag.ExtraOptions...))
	args = stringutils.RemoveDuplicates(append(args, ag.Packages...))

	sc := osutils.SystemCommand{
		Path:                 APT_GET,
		Args:                 args,
		EnvVars:              envVariables,
		ExecDir:              os.TempDir(),
		EnableShellExpansion: true,
	}

	output := sc.Run()
	if output.HasError() {
		return output
	}

	return nil
}
func (mgr *GroupManager) run(c osutils.SystemCommand) error {
	output := c.Run()
	if output.HasError() {
		return output
	}

	return nil

}
func (s *CrontabTestSuite) cleanCrontab(c *C) {
	sc := osutils.SystemCommand{
		Path:                 s.c.Path,
		Args:                 []string{"-u", s.c.User.Username, "-r"},
		ExecDir:              os.TempDir(),
		EnableShellExpansion: true,
	}

	output := sc.Run()
	c.Assert(output.HasError(), Equals, false)
}
Exemple #5
0
func (s *CronTestSuite) cleanCrontab(c *C) {
	u, err := user.Current()
	c.Assert(err, IsNil)

	ct := NewCrontab(u)

	sc := osutils.SystemCommand{
		Path:                 ct.Path,
		Args:                 []string{"-u", u.Username, "-r"},
		ExecDir:              os.TempDir(),
		EnableShellExpansion: true,
	}

	output := sc.Run()
	c.Assert(output.HasError(), Equals, false)
}
Exemple #6
0
func (c *Crontab) Save(cronjobs []Cronjob) error {
	fileName, err := c.writeTmpCrontab(cronjobs)
	if err != nil {
		return err
	}
	defer os.Remove(fileName)

	// -----

	sc := osutils.SystemCommand{
		Path:                 c.Path,
		Args:                 []string{"-u", c.User.Username, fileName},
		ExecDir:              os.TempDir(),
		EnableShellExpansion: true,
	}

	output := sc.Run()
	if output.HasError() {
		return output
	}

	return nil
}